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

SEE ALSO

117       Mojolicious, Mojolicious::Guides, <https://mojolicious.org>.
118
119
120
121perl v5.32.0                      2020-07-28              Mojo::Reactor::EV(3)
Impressum