Leon Timmermans

NAME

Thread::Channel - Fast thread queues

VERSION

version 0.003

SYNOPSIS

 use threads;
 use Thread::Channel;
 my $channel = Thread::Channel->new;

 my $reader = threads->create(sub {
     while (my $line = <>) {
         $channel->enqueue($line)
     };
     $channel->enqueue(undef);
 });

 while (defined(my $line = $channel->dequeue)) {
     print $line;
 }
 $reader->join;

DESCRIPTION

Thread::Channel is an alternative to Thread::Queue. By using a smart serialization ladder, it can achieve high performance without compromizing on flexibility.

METHODS

new()

This constructs a new channel.

enqueue(@items)

This enqueues the message @items to the channel. Note that this list is a single message.

dequeue()

Dequeues a message from queue. Note that this returns a list, not (necessarily) a scalar. If the channel is empty, it will wait until a message arrives.

dequeue_nb()

Dequeues a message from queue. Note that this returns a list, not (necessarily) a scalar. If the channel is empty, it will return an empty list.

SEE ALSO

  • Thread::Queue

  • Sereal

AUTHOR

Leon Timmermans <fawaka@gmail.com>

COPYRIGHT AND LICENSE

This software is copyright (c) 2009 by Leon Timmermans.

This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.