Coro::Channel - message queues
use Coro::Channel; $q1 = new Coro::Channel <maxsize>; $q1->put ("xxx"); print $q1->get; die unless $q1->size;
A Coro::Channel is the equivalent of a unix pipe (and similar to amiga message ports): you can put things into it on one end and read things out of it from the other end. If the capacity of the Channel is maxed out writers will block. Both ends of a Channel can be read/written from by as many coroutines as you want concurrently.
Create a new channel with the given maximum size (practically unlimited if maxsize is omitted). Giving a size of one gives you a traditional channel, i.e. a queue that can store only a single element (which means there will be no buffering, and put will wait until there is a corresponding get call). To buffer one element you have to specify 2, and so on.
maxsize
put
get
2
Put the given scalar into the queue.
Return the next element from the queue, waiting if necessary.
Return the number of elements waiting to be consumed. Please note that:
if ($q->size) { my $data = $q->get; }
is not a race condition but instead works just fine.
Marc Lehmann <schmorp@schmorp.de> http://home.schmorp.de/
To install Coro, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Coro
CPAN shell
perl -MCPAN -e shell install Coro
For more information on module installation, please visit the detailed CPAN module installation guide.