… | |
… | |
41 | |
41 | |
42 | our $idle; # idle coroutine |
42 | our $idle; # idle coroutine |
43 | our $main; # main coroutine |
43 | our $main; # main coroutine |
44 | our $current; # current coroutine |
44 | our $current; # current coroutine |
45 | |
45 | |
46 | our $VERSION = '2.0'; |
46 | our $VERSION = '2.5'; |
47 | |
47 | |
48 | our @EXPORT = qw(async cede schedule terminate current); |
48 | our @EXPORT = qw(async cede schedule terminate current); |
49 | our %EXPORT_TAGS = ( |
49 | our %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 | ); |
… | |
… | |
163 | |
163 | |
164 | Create a new asynchronous process and return it's process object |
164 | Create a new asynchronous process and return it's process object |
165 | (usually unused). When the sub returns the new process is automatically |
165 | (usually unused). When the sub returns the new process is automatically |
166 | terminated. |
166 | terminated. |
167 | |
167 | |
|
|
168 | When the coroutine dies, the program will exit, just as in the main |
|
|
169 | program. |
|
|
170 | |
168 | # create a new coroutine that just prints its arguments |
171 | # create a new coroutine that just prints its arguments |
169 | async { |
172 | async { |
170 | print "@_\n"; |
173 | print "@_\n"; |
171 | } 1,2,3,4; |
174 | } 1,2,3,4; |
172 | |
175 | |
… | |
… | |
229 | } |
232 | } |
230 | |
233 | |
231 | sub new { |
234 | sub new { |
232 | my $class = shift; |
235 | my $class = shift; |
233 | bless { |
236 | bless { |
234 | _coro_state => (new Coro::State $_[0] && \&_newcoro, @_), |
237 | _coro_state => (new Coro::State \&_newcoro, @_), |
235 | }, $class; |
238 | }, $class; |
236 | } |
239 | } |
237 | |
240 | |
238 | =item $process->ready |
241 | =item $process->ready |
239 | |
242 | |
… | |
… | |
241 | |
244 | |
242 | =cut |
245 | =cut |
243 | |
246 | |
244 | =item $process->cancel (arg...) |
247 | =item $process->cancel (arg...) |
245 | |
248 | |
246 | Temrinates the given process and makes it return the given arguments as |
249 | Terminates the given process and makes it return the given arguments as |
247 | status (default: the empty list). |
250 | status (default: the empty list). |
248 | |
251 | |
249 | =cut |
252 | =cut |
250 | |
253 | |
251 | sub cancel { |
254 | sub cancel { |