… | |
… | |
16 | cede; # yield to coroutine |
16 | cede; # yield to coroutine |
17 | print "3\n"; |
17 | print "3\n"; |
18 | cede; # and again |
18 | cede; # and again |
19 | |
19 | |
20 | # use locking |
20 | # use locking |
|
|
21 | use Coro::Semaphore; |
21 | my $lock = new Coro::Semaphore; |
22 | my $lock = new Coro::Semaphore; |
22 | my $locked; |
23 | my $locked; |
23 | |
24 | |
24 | $lock->down; |
25 | $lock->down; |
25 | $locked = 1; |
26 | $locked = 1; |
… | |
… | |
66 | |
67 | |
67 | our $idle; # idle handler |
68 | our $idle; # idle handler |
68 | our $main; # main coroutine |
69 | our $main; # main coroutine |
69 | our $current; # current coroutine |
70 | our $current; # current coroutine |
70 | |
71 | |
71 | our $VERSION = 4.745; |
72 | our $VERSION = 4.8; |
72 | |
73 | |
73 | our @EXPORT = qw(async async_pool cede schedule terminate current unblock_sub); |
74 | our @EXPORT = qw(async async_pool cede schedule terminate current unblock_sub); |
74 | our %EXPORT_TAGS = ( |
75 | our %EXPORT_TAGS = ( |
75 | prio => [qw(PRIO_MAX PRIO_HIGH PRIO_NORMAL PRIO_LOW PRIO_IDLE PRIO_MIN)], |
76 | prio => [qw(PRIO_MAX PRIO_HIGH PRIO_NORMAL PRIO_LOW PRIO_IDLE PRIO_MIN)], |
76 | ); |
77 | ); |
… | |
… | |
220 | terminate or join on it (although you are allowed to), and you get a |
221 | terminate or join on it (although you are allowed to), and you get a |
221 | coroutine that might have executed other code already (which can be good |
222 | coroutine that might have executed other code already (which can be good |
222 | or bad :). |
223 | or bad :). |
223 | |
224 | |
224 | On the plus side, this function is faster than creating (and destroying) |
225 | On the plus side, this function is faster than creating (and destroying) |
225 | a completely new coroutine, so if you need a lot of generic coroutines in |
226 | a completly new coroutine, so if you need a lot of generic coroutines in |
226 | quick successsion, use C<async_pool>, not C<async>. |
227 | quick successsion, use C<async_pool>, not C<async>. |
227 | |
228 | |
228 | The code block is executed in an C<eval> context and a warning will be |
229 | The code block is executed in an C<eval> context and a warning will be |
229 | issued in case of an exception instead of terminating the program, as |
230 | issued in case of an exception instead of terminating the program, as |
230 | C<async> does. As the coroutine is being reused, stuff like C<on_destroy> |
231 | C<async> does. As the coroutine is being reused, stuff like C<on_destroy> |