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

Comparing Coro/Coro.pm (file contents):
Revision 1.195 by root, Wed Jul 23 22:15:25 2008 UTC vs.
Revision 1.196 by root, Sat Aug 30 03:07:46 2008 UTC

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
309This 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
310coroutine and wait for events: first you remember the current coroutine in 310coroutine and wait for events: first you remember the current coroutine in
311a 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
312>> 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
313yourself 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,
314so 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
315status in a variable. 315status in a variable.
316 316
317The canonical way to wait on external events is this: 317The canonical way to wait on external events is this:
318 318
319 { 319 {
358Kills/terminates/cancels all coroutines except the currently running 358Kills/terminates/cancels all coroutines except the currently running
359one. 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
360usually only one of them should inherit the running coroutines. 360usually only one of them should inherit the running coroutines.
361 361
362Note 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,
363you 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
364program calls this function, there will be some one-time resource leak. 364program calls this function, there will be some one-time resource leak.
365 365
366=cut 366=cut
367 367
368sub terminate { 368sub terminate {
417once 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
418priority that were put into the ready queue earlier have been resumed. 418priority that were put into the ready queue earlier have been resumed.
419 419
420=item $is_ready = $coroutine->is_ready 420=item $is_ready = $coroutine->is_ready
421 421
422Return wether the coroutine is currently the ready queue or not, 422Return whether the coroutine is currently the ready queue or not,
423 423
424=item $coroutine->cancel (arg...) 424=item $coroutine->cancel (arg...)
425 425
426Terminates the given coroutine and makes it return the given arguments as 426Terminates the given coroutine and makes it return the given arguments as
427status (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