| line | stmt | bran | cond | sub | pod | time | code | 
| 1 |  |  |  |  |  |  | package EntityModel::EventLoop::IO::Async; | 
| 2 |  |  |  |  |  |  | # ABSTRACT: Wrapper around an IO::Async::Loop instance | 
| 3 |  |  |  |  |  |  | use EntityModel::Class { | 
| 4 | 2 |  |  |  |  | 23 | _isa => [qw(EntityModel::EventLoop)], | 
| 5 |  |  |  |  |  |  | loop => 'IO::Async::Loop', | 
| 6 | 2 |  |  | 2 |  | 30285 | }; | 
|  | 2 |  |  |  |  | 151866 |  | 
| 7 |  |  |  |  |  |  |  | 
| 8 |  |  |  |  |  |  | our $VERSION = '0.001'; | 
| 9 |  |  |  |  |  |  |  | 
| 10 |  |  |  |  |  |  | =head1 NAME | 
| 11 |  |  |  |  |  |  |  | 
| 12 |  |  |  |  |  |  | EntityModel::EventLoop::IO::Async - handler for L object. | 
| 13 |  |  |  |  |  |  |  | 
| 14 |  |  |  |  |  |  | =head1 VERSION | 
| 15 |  |  |  |  |  |  |  | 
| 16 |  |  |  |  |  |  | version 0.001 | 
| 17 |  |  |  |  |  |  |  | 
| 18 |  |  |  |  |  |  | =head1 DESCRIPTION | 
| 19 |  |  |  |  |  |  |  | 
| 20 |  |  |  |  |  |  | Support for an L event loop. | 
| 21 |  |  |  |  |  |  |  | 
| 22 |  |  |  |  |  |  | =head1 METHODS | 
| 23 |  |  |  |  |  |  |  | 
| 24 |  |  |  |  |  |  | =cut | 
| 25 |  |  |  |  |  |  |  | 
| 26 |  |  |  |  |  |  | =head2 loop | 
| 27 |  |  |  |  |  |  |  | 
| 28 |  |  |  |  |  |  | Direct accessor for the L object, can be used to provide a specific loop: | 
| 29 |  |  |  |  |  |  |  | 
| 30 |  |  |  |  |  |  | $el->loop(IO::Async::Loop::Epoll->new); | 
| 31 |  |  |  |  |  |  |  | 
| 32 |  |  |  |  |  |  | =cut | 
| 33 |  |  |  |  |  |  |  | 
| 34 |  |  |  |  |  |  | =head2 event_loop | 
| 35 |  |  |  |  |  |  |  | 
| 36 |  |  |  |  |  |  | Returns the event loop, instantiating a new one if necessary. Should be used in preference | 
| 37 |  |  |  |  |  |  | to L for making sure that a valid event loop is available, since this will raise an | 
| 38 |  |  |  |  |  |  | exception if no event loop could be instantiated. | 
| 39 |  |  |  |  |  |  |  | 
| 40 |  |  |  |  |  |  | =cut | 
| 41 |  |  |  |  |  |  |  | 
| 42 |  |  |  |  |  |  | sub event_loop { | 
| 43 |  |  |  |  |  |  | my $self = shift; | 
| 44 |  |  |  |  |  |  | $self->loop(IO::Async::Loop->new) unless $self->loop; | 
| 45 |  |  |  |  |  |  | return $self->loop || die "No event loop available"; | 
| 46 |  |  |  |  |  |  | } | 
| 47 |  |  |  |  |  |  |  | 
| 48 |  |  |  |  |  |  | =head2 defer | 
| 49 |  |  |  |  |  |  |  | 
| 50 |  |  |  |  |  |  | Defers execution of the given codeblock using Llater( $code )>. | 
| 51 |  |  |  |  |  |  |  | 
| 52 |  |  |  |  |  |  | =cut | 
| 53 |  |  |  |  |  |  |  | 
| 54 |  |  |  |  |  |  | sub defer { | 
| 55 |  |  |  |  |  |  | my $self = shift; | 
| 56 |  |  |  |  |  |  | my $code = shift; | 
| 57 |  |  |  |  |  |  | $self->event_loop->later($code); | 
| 58 |  |  |  |  |  |  | $self; | 
| 59 |  |  |  |  |  |  | } | 
| 60 |  |  |  |  |  |  |  | 
| 61 |  |  |  |  |  |  | =head2 sleep | 
| 62 |  |  |  |  |  |  |  | 
| 63 |  |  |  |  |  |  | Runs the given code block after an interval. | 
| 64 |  |  |  |  |  |  |  | 
| 65 |  |  |  |  |  |  | Instance method which expects an interval (in seconds) and a single coderef. | 
| 66 |  |  |  |  |  |  |  | 
| 67 |  |  |  |  |  |  | =cut | 
| 68 |  |  |  |  |  |  |  | 
| 69 |  |  |  |  |  |  | sub sleep { | 
| 70 |  |  |  |  |  |  | my $self = shift; | 
| 71 |  |  |  |  |  |  | my ($interval, $code) = @_; | 
| 72 |  |  |  |  |  |  | $self->event_loop->enqueue_timer( | 
| 73 |  |  |  |  |  |  | delay => $interval, | 
| 74 |  |  |  |  |  |  | code => $code | 
| 75 |  |  |  |  |  |  | ); | 
| 76 |  |  |  |  |  |  | return $self; | 
| 77 |  |  |  |  |  |  | } | 
| 78 |  |  |  |  |  |  |  | 
| 79 |  |  |  |  |  |  | 1; | 
| 80 |  |  |  |  |  |  |  | 
| 81 |  |  |  |  |  |  | __END__ |