Skip to content

Commit

Permalink
add an example for watching a file descriptor
Browse files Browse the repository at this point in the history
  • Loading branch information
kraih committed Feb 15, 2015
1 parent fa66e86 commit e24f589
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions lib/Mojo/IOLoop.pm
Expand Up @@ -613,6 +613,13 @@ loop object from everywhere inside the process.
my $id = Mojo::IOLoop->timer(3 => sub { say 'Timeout!' });
Mojo::IOLoop->singleton->reactor->again($id);
# Watch if file descriptor becomes readable
my $handle = IO::Handle->new_from_fd($fd, 'r');
Mojo::IOLoop->singleton->reactor->io($handle => sub {
my ($reactor, $writable) = @_;
say $writable ? 'Descriptor is writable' : 'Descriptor is readable';
})->watch($handle, 1, 0);
=head2 start
Mojo::IOLoop->start;
Expand Down

0 comments on commit e24f589

Please sign in to comment.