POE::Queue - documentation for POE's priority queue interface |
POE::Queue - documentation for POE's priority queue interface
$queue = POE::Queue::Foo->new();
$payload_id = $queue->enqueue($priority, $payload);
($priority, $id, $payload) = $queue->dequeue_next();
$next_priority = $queue->get_next_priority(); $item_count = $queue->get_item_count();
($priority, $id, $payload) = $q->remove_item($id, \&filter);
@items = $q->remove_items(\&filter, $count); # $count is optional
@items = $q->peek_items(\&filter, $count); # $count is optional
$new_priority = $q->adjust_priority($id, \&filter, $delta); $new_priority = $q->set_priority($id, \&filter, $priority);
Priority queues are basically lists of arbitrary things that allow items to be inserted arbitrarily but that return them in a particular order. The order they are returned in is determined by each item's priority.
Priorities may represent anything, as long as they are numbers and represent an order from smallest to largest. Items with the same priority are entered into a queue in FIFO order. That is, items at the same priority are dequeued in the order they achieved a that priority.
POE uses priority queues to store and sequence its events. Queue items are events, and their priorities are the UNIX epoch times they are due.
The payload will be placed into the queue in priority order, from lowest to highest. The new payload will follow any others that already exist in the queue at the specified priority.
sub filter { my $payload = $_[0]; return 1 if $payload eq "wombat"; return 0; }
Returns undef on failure, and sets $! to the reason why the call failed: ESRCH if the $id did not exist in the queue, or EPERM if the filter function returned 0.
[ $priority, $id, $payload ].
This filter does not allow anything to be removed.
sub filter { 0 }
The $count is optional. If supplied, remove_items()
will remove at
most $count items. This is useful when you know how many items exist
in the queue to begin with, as POE sometimes does. If a $count is
supplied, it should be correct. There is no telling which items are
removed by remove_items()
if $count is too low.
[ $priority, $id, $payload ]
This filter only lets you move monkeys.
sub filter { return $_[0]->[TYPE] & IS_A_MONKEY; }
The $count is optional. If supplied, peek_items()
will return at most
$count items. This is useful when you know how many items exist in
the queue to begin with, as POE sometimes does. If a $count is
supplied, it should be correct. There is no telling which items are
returned by peek_items()
if $count is too low.
This filter function allows anything to be removed.
sub filter { 1 }
POE, the POE::Queue::Array manpage
None known.
Please see POE for more information about authors, contributors, and POE's licensing.
POE::Queue - documentation for POE's priority queue interface |