NAME

Coro::PrioChannel::Multi - Multiple-listener priority message queues for Coro

VERSION

version 0.004

SYNOPSIS

use Coro::PrioChannel::Multi;

my $q = Coro::PrioChannel::Multi->new($maxsize);
$q->put("xxx"[, $prio]);

my $l = $q->listen();
print $l->get; # from Coro::PrioChannel

DESCRIPTION

A Coro::PrioChannel::Multi is exactly like Coro::PrioChannel, but with the ability to add (and lose) listeners.

Unlike Coro::Channel, you do have to load this module directly.

Each item that is put into the channel will get sent to all listener(s). However, there is no deep copy here, if the item put in is a reference, all listeners will receive a reference to the same object, which will allow each listening thread to modify it before the next thread sees it. This could be construed as a feature.

Messages put into the channel before any listener is set up will be lost. Messages put into the channel before a listener is set up will not be resent to that listener, even if the message is still in some other listener's channel.

METHODS

new

Create a new multi-channel with the given maximum size. Giving a size of one defeats the purpose of a priority queue. However, with multiple listeners, this should ensure that each listener deals with the item before we add the next item.

clean

Clears out any channels that have gone away. Shouldn't normally be needed as the object will generally self-clean.

The concept is that a listener may no longer be interested, and has let its channel listener go out of scope, which will leave a hole in the list of listeners. This method simply clears out the holes.

number_of_listeners

Returns a count of the number of listeners still attached to this channel.

listen

Set up a new listener for the channel. Returns a Coro::PrioChannel object that you issue a ->get against. For example:

my $l = $cpcm->listen();
while (my $item = $l->get())
{
    #...
}
put

Pass a message to all (current) listeners. Optionally provide a priority between Coro::PRIO_MIN and Coro::PRIO_MAX.

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.