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

Comparing Coro/Coro.pm (file contents):
Revision 1.86 by root, Sat Nov 25 01:14:11 2006 UTC vs.
Revision 1.89 by root, Mon Nov 27 02:01:33 2006 UTC

41 41
42our $idle; # idle handler 42our $idle; # idle handler
43our $main; # main coroutine 43our $main; # main coroutine
44our $current; # current coroutine 44our $current; # current coroutine
45 45
46our $VERSION = '2.5'; 46our $VERSION = '3.0';
47 47
48our @EXPORT = qw(async cede schedule terminate current); 48our @EXPORT = qw(async cede schedule terminate current);
49our %EXPORT_TAGS = ( 49our %EXPORT_TAGS = (
50 prio => [qw(PRIO_MAX PRIO_HIGH PRIO_NORMAL PRIO_LOW PRIO_IDLE PRIO_MIN)], 50 prio => [qw(PRIO_MAX PRIO_HIGH PRIO_NORMAL PRIO_LOW PRIO_IDLE PRIO_MIN)],
51); 51);
171 171
172Create a new asynchronous process and return it's process object 172Create a new asynchronous process and return it's process object
173(usually unused). When the sub returns the new process is automatically 173(usually unused). When the sub returns the new process is automatically
174terminated. 174terminated.
175 175
176Calling C<exit> in a coroutine will not work correctly, so do not do that.
177
176When the coroutine dies, the program will exit, just as in the main 178When the coroutine dies, the program will exit, just as in the main
177program. 179program.
178 180
179 # create a new coroutine that just prints its arguments 181 # create a new coroutine that just prints its arguments
180 async { 182 async {
230Create a new process and return it. When the sub returns the process 232Create a new process and return it. When the sub returns the process
231automatically terminates as if C<terminate> with the returned values were 233automatically terminates as if C<terminate> with the returned values were
232called. To make the process run you must first put it into the ready queue 234called. To make the process run you must first put it into the ready queue
233by calling the ready method. 235by calling the ready method.
234 236
237Calling C<exit> in a coroutine will not work correctly, so do not do that.
238
235=cut 239=cut
236 240
237sub _new_coro { 241sub _new_coro {
238 $current->_clear_idle_sp; # (re-)set the idle sp on the following cede
239 _set_cede_self; # ensures that cede cede's us first
240 cede;
241 terminate &{+shift}; 242 terminate &{+shift};
242} 243}
243 244
244sub new { 245sub new {
245 my $class = shift; 246 my $class = shift;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines