Skip to content

Commit

Permalink
more examples for converting a file descriptor into a handle
Browse files Browse the repository at this point in the history
  • Loading branch information
kraih committed Feb 15, 2015
1 parent e24f589 commit 230bebd
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 4 deletions.
4 changes: 2 additions & 2 deletions lib/Mojo/IOLoop.pm
Expand Up @@ -613,11 +613,11 @@ 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
# Turn file descriptor into handle and watch if it 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';
say $writable ? 'Handle is writable' : 'Handle is readable';
})->watch($handle, 1, 0);
=head2 start
Expand Down
4 changes: 3 additions & 1 deletion lib/Mojo/Reactor/EV.pm
Expand Up @@ -80,8 +80,10 @@ Mojo::Reactor::EV - Low-level event reactor with libev support
use Mojo::Reactor::EV;
# Watch if handle becomes readable or writable
# Turn file descriptor into handle and watch if it becomes readable or
# writable
my $reactor = Mojo::Reactor::EV->new;
my $handle = IO::Handle->new_from_fd($fd, 'r');
$reactor->io($handle => sub {
my ($reactor, $writable) = @_;
say $writable ? 'Handle is writable' : 'Handle is readable';
Expand Down
4 changes: 3 additions & 1 deletion lib/Mojo/Reactor/Poll.pm
Expand Up @@ -141,8 +141,10 @@ Mojo::Reactor::Poll - Low-level event reactor with poll support
use Mojo::Reactor::Poll;
# Watch if handle becomes readable or writable
# Turn file descriptor into handle and watch if it becomes readable or
# writable
my $reactor = Mojo::Reactor::Poll->new;
my $handle = IO::Handle->new_from_fd($fd, 'r');
$reactor->io($handle => sub {
my ($reactor, $writable) = @_;
say $writable ? 'Handle is writable' : 'Handle is readable';
Expand Down

0 comments on commit 230bebd

Please sign in to comment.