NAME
Coro::PrioChannel - Priority message queues for Coro
VERSION
version 0.004
SYNOPSIS
use Coro::PrioChannel;
my $q = Coro::PrioChannel->new($maxsize);
$q->put("xxx"[, $prio]);
print $q->get;
DESCRIPTION
A Coro::PrioChannel is exactly like Coro::Channel, but with priorities. The priorities are the same as for Coro itself.
Unlike Coro::Channel, you do have to load this module directly.
METHODS
- new
-
Create a new channel with the given maximum size. Giving a size of one defeats the purpose of a priority queue. Optionally specify the amount of time spent in the queue before an item's priority is boosted to avoid starvation.
- put
-
Put the given scalar into the queue. Optionally provide a priority between Coro::PRIO_MIN and Coro::PRIO_MAX.
- get
-
Return the next element from the queue at the highest priority, waiting if necessary.
TODO: allow an optional parameter to wait for a message of a minimum priority level (i.e., ignore messages of lower priority).
- reprioritize
-
Reprioritizes the queue, boosting the priority of elements that have been in the queue for longer than the reprioritization parameter (passed to the constructor). This method is called automatically by put() and should not need to be called directly in normal circumstances.
- shutdown
-
Same as Coro::Channel.
- size
-
Same as Coro::Channel.
An optional parameter allows you to specify the minimum priority level that you want to check the size against, i.e., to ignore messages of lower priority. This can be used for example if you're in the middle of an action and you want to check if there is a higher-priority message to deal with before resuming the current activity. This will not block.
AUTHOR
Darin McBride <dmcbride@cpan.org>
COPYRIGHT AND LICENSE
This software is copyright (c) 2012 by Darin McBride.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.