Created
July 9, 2009 10:10
-
-
Save bingos/143552 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use strict; | |
use warnings; | |
use threads; | |
use Thread::Queue; | |
use POE; | |
$|=1; | |
my $queue = Thread::Queue->new; | |
async { $queue->enqueue( $_ ) while defined( $_ = <STDIN> ); }->detach; | |
POE::Session->create( | |
package_states => [ | |
main => [qw(_start _check)], | |
], | |
); | |
$poe_kernel->run(); | |
exit 0; | |
sub _start { | |
my ($kernel,$heap) = @_[KERNEL,HEAP]; | |
$kernel->yield( '_check' ); | |
return; | |
} | |
sub _check { | |
my ($kernel,$heap) = @_[KERNEL,HEAP]; | |
while ( $queue->pending ) { | |
my $input = $queue->dequeue; | |
print $input; | |
} | |
$kernel->yield( '_check' ) if scalar threads->list(); | |
return; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment