… | |
… | |
4 | |
4 | |
5 | =head1 SYNOPSIS |
5 | =head1 SYNOPSIS |
6 | |
6 | |
7 | use Coro; |
7 | use Coro; |
8 | use Coro::EV; |
8 | use Coro::EV; |
|
|
9 | |
|
|
10 | EV::loop; |
9 | |
11 | |
10 | =head1 DESCRIPTION |
12 | =head1 DESCRIPTION |
11 | |
13 | |
12 | This module does two things: First, it offers some utility functions that |
14 | This module does two things: First, it offers some utility functions that |
13 | might be useful for coroutines, and secondly, it integrates Coro into the |
15 | might be useful for coroutines, and secondly, it integrates Coro into the |
… | |
… | |
20 | |
22 | |
21 | That means that coroutines with the same or higher pripority as the |
23 | That means that coroutines with the same or higher pripority as the |
22 | coroutine running the main loop will inhibit event processing, while |
24 | coroutine running the main loop will inhibit event processing, while |
23 | coroutines of lower priority will get the CPU, but cannot completeley |
25 | coroutines of lower priority will get the CPU, but cannot completeley |
24 | inhibit event processing. |
26 | inhibit event processing. |
|
|
27 | |
|
|
28 | =head2 RUNNING WITH OR WITHOUT A MAINLOOP |
|
|
29 | |
|
|
30 | In general, you should always run EV::loop, either in your main program, |
|
|
31 | or in a separate coroutine. If you don't do that and all coroutines start |
|
|
32 | waiting for some events, this module will run the event loop once, but |
|
|
33 | this is very inefficient. |
25 | |
34 | |
26 | =head1 FUNCTIONS |
35 | =head1 FUNCTIONS |
27 | |
36 | |
28 | =over 4 |
37 | =over 4 |
29 | |
38 | |
… | |
… | |
46 | our $VERSION = '2.1'; |
55 | our $VERSION = '2.1'; |
47 | |
56 | |
48 | local $^W = 0; # avoid redefine warning for Coro::ready; |
57 | local $^W = 0; # avoid redefine warning for Coro::ready; |
49 | XSLoader::load __PACKAGE__, $VERSION; |
58 | XSLoader::load __PACKAGE__, $VERSION; |
50 | } |
59 | } |
|
|
60 | |
|
|
61 | unshift @AnyEvent::REGISTRY, [Coro::EV => "EV::AnyEvent"]; |
51 | |
62 | |
52 | # relatively inefficient |
63 | # relatively inefficient |
53 | our $ev_idle = new Coro sub { |
64 | our $ev_idle = new Coro sub { |
54 | while () { |
65 | while () { |
55 | EV::loop EV::LOOP_ONESHOT; |
66 | EV::loop EV::LOOP_ONESHOT; |