Last active
August 29, 2015 14:11
-
-
Save preaction/afa3588b56971cc86776 to your computer and use it in GitHub Desktop.
Read from /dev/urandom
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 Mojo::IOLoop::Stream; | |
my $stream = Mojo::IOLoop::Stream->new(IO::File->new("</dev/urandom")); | |
$stream->on(read => sub { | |
my ($stream, $bytes) = @_; | |
print STDERR "Read from stream\n"; | |
}); | |
$stream->on(error=>sub { | |
my ($stream, $err) = @_; | |
print STDERR "ERROR $err\n"; | |
}); | |
$stream->on(close=>sub { | |
my ($stream) = @_; | |
print STDERR "CLOSED\n"; #this fires right away | |
}); | |
$stream->start; | |
$stream->reactor->start; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment