1Mojo::Reactor::EV(3)  User Contributed Perl Documentation Mojo::Reactor::EV(3)
2
3
4

NAME

6       Mojo::Reactor::EV - Low-level event reactor with libev support
7

SYNOPSIS

9         use Mojo::Reactor::EV;
10
11         # Watch if handle becomes readable or writable
12         my $reactor = Mojo::Reactor::EV->new;
13         $reactor->io($first => sub {
14           my ($reactor, $writable) = @_;
15           say $writable ? 'First handle is writable' : 'First handle is readable';
16         });
17
18         # Change to watching only if handle becomes writable
19         $reactor->watch($first, 0, 1);
20
21         # Turn file descriptor into handle and watch if it becomes readable
22         my $second = IO::Handle->new_from_fd($fd, 'r');
23         $reactor->io($second => sub {
24           my ($reactor, $writable) = @_;
25           say $writable ? 'Second handle is writable' : 'Second handle is readable';
26         })->watch($second, 1, 0);
27
28         # Add a timer
29         $reactor->timer(15 => sub {
30           my $reactor = shift;
31           $reactor->remove($first);
32           $reactor->remove($second);
33           say 'Timeout!';
34         });
35
36         # Start reactor if necessary
37         $reactor->start unless $reactor->is_running;
38

DESCRIPTION

40       Mojo::Reactor::EV is a low-level event reactor based on EV (4.0+).
41

EVENTS

43       Mojo::Reactor::EV inherits all events from Mojo::Reactor::Poll.
44

METHODS

46       Mojo::Reactor::EV inherits all methods from Mojo::Reactor::Poll and
47       implements the following new ones.
48
49   again
50         $reactor->again($id);
51
52       Restart timer. Note that this method requires an active timer.
53
54   is_running
55         my $bool = $reactor->is_running;
56
57       Check if reactor is running.
58
59   new
60         my $reactor = Mojo::Reactor::EV->new;
61
62       Construct a new Mojo::Reactor::EV object.
63
64   one_tick
65         $reactor->one_tick;
66
67       Run reactor until an event occurs or no events are being watched
68       anymore.
69
70         # Don't block longer than 0.5 seconds
71         my $id = $reactor->timer(0.5 => sub {});
72         $reactor->one_tick;
73         $reactor->remove($id);
74
75   recurring
76         my $id = $reactor->recurring(0.25 => sub {...});
77
78       Create a new recurring timer, invoking the callback repeatedly after a
79       given amount of time in seconds.
80
81   start
82         $reactor->start;
83
84       Start watching for I/O and timer events, this will block until "stop"
85       is called or no events are being watched anymore.
86
87         # Start reactor only if it is not running already
88         $reactor->start unless $reactor->is_running;
89
90   stop
91         $reactor->stop;
92
93       Stop watching for I/O and timer events.
94
95   timer
96         my $id = $reactor->timer(0.5 => sub {...});
97
98       Create a new timer, invoking the callback after a given amount of time
99       in seconds.
100
101   watch
102         $reactor = $reactor->watch($handle, $readable, $writable);
103
104       Change I/O events to watch handle for with true and false values. Note
105       that this method requires an active I/O watcher.
106
107         # Watch only for readable events
108         $reactor->watch($handle, 1, 0);
109
110         # Watch only for writable events
111         $reactor->watch($handle, 0, 1);
112
113         # Watch for readable and writable events
114         $reactor->watch($handle, 1, 1);
115
116         # Pause watching for events
117         $reactor->watch($handle, 0, 0);
118

SEE ALSO

120       Mojolicious, Mojolicious::Guides, <https://mojolicious.org>.
121
122
123
124perl v5.30.0                      2019-07-26              Mojo::Reactor::EV(3)
Impressum