… | |
… | |
8 | use Coro::EV; |
8 | use Coro::EV; |
9 | |
9 | |
10 | EV::READ & Coro::EV::timed_io_once $fh, EV::READ, 60 |
10 | EV::READ & Coro::EV::timed_io_once $fh, EV::READ, 60 |
11 | or die "timeout\n"; |
11 | or die "timeout\n"; |
12 | |
12 | |
13 | EV::loop; |
13 | EV::run; |
14 | |
14 | |
15 | =head1 DESCRIPTION |
15 | =head1 DESCRIPTION |
16 | |
16 | |
17 | This module does two things: First, it offers some utility functions that |
17 | This module does two things: First, it offers some utility functions that |
18 | might be useful for threads (although L<Coro::AnyEvent> offers more and |
18 | might be useful for threads (although L<Coro::AnyEvent> offers more and |
19 | more portable functions), and secondly, it integrates Coro into the EV |
19 | more portable functions), and secondly, it integrates Coro into the EV |
20 | main loop: |
20 | main loop: |
21 | |
21 | |
22 | Before the process blocks (in EV::loop) to wait for events, this module |
22 | Before the process blocks (in EV::run) to wait for events, this module |
23 | will schedule and run all ready (= runnable) threads of the same or |
23 | will schedule and run all ready (= runnable) threads of the same or |
24 | higher priority. After that, it will cede once to a threads of lower |
24 | higher priority. After that, it will cede once to a threads of lower |
25 | priority, then continue in the event loop. |
25 | priority, then continue in the event loop. |
26 | |
26 | |
27 | That means that threads with the same or higher priority as the threads |
27 | That means that threads with the same or higher priority as the threads |
… | |
… | |
30 | processing. Note that for that to work you actually have to run the EV |
30 | processing. Note that for that to work you actually have to run the EV |
31 | event loop in some thread. |
31 | event loop in some thread. |
32 | |
32 | |
33 | =head1 RUNNING WITH OR WITHOUT A MAINLOOP |
33 | =head1 RUNNING WITH OR WITHOUT A MAINLOOP |
34 | |
34 | |
35 | In general, you should always run EV::loop, either in your main program, |
35 | In general, you should always run EV::run, either in your main program, |
36 | or in a separate coroutine. If you don't do that and all coroutines |
36 | or in a separate coroutine. If you don't do that and all coroutines |
37 | start waiting for some events, this module will run the event loop once, |
37 | start waiting for some events, this module will run the event loop once, |
38 | but this is very inefficient and will also not make it possible to run |
38 | but this is very inefficient and will also not make it possible to run |
39 | background threads. |
39 | background threads. |
40 | |
40 | |
41 | To run the EV event loop in a separate thread, you can simply do this: |
41 | To run the EV event loop in a separate thread, you can simply do this: |
42 | |
42 | |
43 | async { EV::loop }; |
43 | async { EV::run }; |
44 | |
44 | |
45 | =head1 FUNCTIONS |
45 | =head1 FUNCTIONS |
46 | |
46 | |
47 | =over 4 |
47 | =over 4 |
48 | |
48 | |