ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/Coro/Coro.pm
(Generate patch)

Comparing Coro/Coro.pm (file contents):
Revision 1.186 by root, Sun May 25 01:32:36 2008 UTC vs.
Revision 1.196 by root, Sat Aug 30 03:07:46 2008 UTC

66 66
67our $idle; # idle handler 67our $idle; # idle handler
68our $main; # main coroutine 68our $main; # main coroutine
69our $current; # current coroutine 69our $current; # current coroutine
70 70
71our $VERSION = '4.72'; 71our $VERSION = 4.745;
72 72
73our @EXPORT = qw(async async_pool cede schedule terminate current unblock_sub); 73our @EXPORT = qw(async async_pool cede schedule terminate current unblock_sub);
74our %EXPORT_TAGS = ( 74our %EXPORT_TAGS = (
75 prio => [qw(PRIO_MAX PRIO_HIGH PRIO_NORMAL PRIO_LOW PRIO_IDLE PRIO_MIN)], 75 prio => [qw(PRIO_MAX PRIO_HIGH PRIO_NORMAL PRIO_LOW PRIO_IDLE PRIO_MIN)],
76); 76);
81=item $Coro::main 81=item $Coro::main
82 82
83This variable stores the coroutine object that represents the main 83This variable stores the coroutine object that represents the main
84program. While you cna C<ready> it and do most other things you can do to 84program. While you cna C<ready> it and do most other things you can do to
85coroutines, it is mainly useful to compare again C<$Coro::current>, to see 85coroutines, it is mainly useful to compare again C<$Coro::current>, to see
86wether you are running in the main program or not. 86whether you are running in the main program or not.
87 87
88=cut 88=cut
89 89
90$main = new Coro; 90$main = new Coro;
91 91
266 _pool_2 $cb; 266 _pool_2 $cb;
267 &schedule; 267 &schedule;
268 } 268 }
269 }; 269 };
270 270
271 if ($@) {
271 last if $@ eq "\3async_pool terminate\2\n"; 272 last if $@ eq "\3async_pool terminate\2\n";
272 warn $@ if $@; 273 warn $@;
274 }
273 } 275 }
274} 276}
275 277
276sub async_pool(&@) { 278sub async_pool(&@) {
277 # this is also inlined into the unlock_scheduler 279 # this is also inlined into the unlock_scheduler
307This makes C<schedule> I<the> generic method to use to block the current 309This makes C<schedule> I<the> generic method to use to block the current
308coroutine and wait for events: first you remember the current coroutine in 310coroutine and wait for events: first you remember the current coroutine in
309a variable, then arrange for some callback of yours to call C<< ->ready 311a variable, then arrange for some callback of yours to call C<< ->ready
310>> on that once some event happens, and last you call C<schedule> to put 312>> on that once some event happens, and last you call C<schedule> to put
311yourself to sleep. Note that a lot of things can wake your coroutine up, 313yourself to sleep. Note that a lot of things can wake your coroutine up,
312so you need to check wether the event indeed happened, e.g. by storing the 314so you need to check whether the event indeed happened, e.g. by storing the
313status in a variable. 315status in a variable.
314 316
315The canonical way to wait on external events is this: 317The canonical way to wait on external events is this:
316 318
317 { 319 {
356Kills/terminates/cancels all coroutines except the currently running 358Kills/terminates/cancels all coroutines except the currently running
357one. This is useful after a fork, either in the child or the parent, as 359one. This is useful after a fork, either in the child or the parent, as
358usually only one of them should inherit the running coroutines. 360usually only one of them should inherit the running coroutines.
359 361
360Note that while this will try to free some of the main programs resources, 362Note that while this will try to free some of the main programs resources,
361you cnanot free all of them, so if a coroutine that is not the main 363you cannot free all of them, so if a coroutine that is not the main
362program calls this function, there will be some one-time resource leak. 364program calls this function, there will be some one-time resource leak.
363 365
364=cut 366=cut
365 367
366sub terminate { 368sub terminate {
415once all the coroutines of higher priority and all coroutines of the same 417once all the coroutines of higher priority and all coroutines of the same
416priority that were put into the ready queue earlier have been resumed. 418priority that were put into the ready queue earlier have been resumed.
417 419
418=item $is_ready = $coroutine->is_ready 420=item $is_ready = $coroutine->is_ready
419 421
420Return wether the coroutine is currently the ready queue or not, 422Return whether the coroutine is currently the ready queue or not,
421 423
422=item $coroutine->cancel (arg...) 424=item $coroutine->cancel (arg...)
423 425
424Terminates the given coroutine and makes it return the given arguments as 426Terminates the given coroutine and makes it return the given arguments as
425status (default: the empty list). Never returns if the coroutine is the 427status (default: the empty list). Never returns if the coroutine is the

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines