Skip to content

Instantly share code, notes, and snippets.

@preaction
Last active August 29, 2015 14:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save preaction/afa3588b56971cc86776 to your computer and use it in GitHub Desktop.
Save preaction/afa3588b56971cc86776 to your computer and use it in GitHub Desktop.
Read from /dev/urandom
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