Coro::Channel - message queues |
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 pipe: you can put things into it on one end end read things out of it from the other hand. If the capacity of the Channel is maxed out writers will block. Both ends of a Channel can be read/written from as many coroutines as you want.
maxsize
is omitted). Giving a size of one gives you a traditional channel, i.e. a
queue that can store only a single element.
put($scalar)
if ($q->size) { my $data = $q->get; }
is NOT a race condition but works fine.
Marc Lehmann <pcg@goof.com> http://www.goof.com/pcg/marc/
Coro::Channel - message queues |