… | |
… | |
50 | |
50 | |
51 | our $idle; # idle handler |
51 | our $idle; # idle handler |
52 | our $main; # main coroutine |
52 | our $main; # main coroutine |
53 | our $current; # current coroutine |
53 | our $current; # current coroutine |
54 | |
54 | |
55 | our $VERSION = '3.8'; |
55 | our $VERSION = '4.0'; |
56 | |
56 | |
57 | our @EXPORT = qw(async async_pool cede schedule terminate current unblock_sub); |
57 | our @EXPORT = qw(async async_pool cede schedule terminate current unblock_sub); |
58 | our %EXPORT_TAGS = ( |
58 | our %EXPORT_TAGS = ( |
59 | prio => [qw(PRIO_MAX PRIO_HIGH PRIO_NORMAL PRIO_LOW PRIO_IDLE PRIO_MIN)], |
59 | prio => [qw(PRIO_MAX PRIO_HIGH PRIO_NORMAL PRIO_LOW PRIO_IDLE PRIO_MIN)], |
60 | ); |
60 | ); |
… | |
… | |
187 | |
187 | |
188 | Create a new asynchronous coroutine and return it's coroutine object |
188 | Create a new asynchronous coroutine and return it's coroutine object |
189 | (usually unused). When the sub returns the new coroutine is automatically |
189 | (usually unused). When the sub returns the new coroutine is automatically |
190 | terminated. |
190 | terminated. |
191 | |
191 | |
|
|
192 | See the C<Coro::State::new> constructor for info about the coroutine |
|
|
193 | environment. |
|
|
194 | |
192 | Calling C<exit> in a coroutine will do the same as calling exit outside |
195 | Calling C<exit> in a coroutine will do the same as calling exit outside |
193 | the coroutine. Likewise, when the coroutine dies, the program will exit, |
196 | the coroutine. Likewise, when the coroutine dies, the program will exit, |
194 | just as it would in the main program. |
197 | just as it would in the main program. |
195 | |
198 | |
196 | # create a new coroutine that just prints its arguments |
199 | # create a new coroutine that just prints its arguments |
… | |
… | |
216 | issued in case of an exception instead of terminating the program, as |
219 | issued in case of an exception instead of terminating the program, as |
217 | C<async> does. As the coroutine is being reused, stuff like C<on_destroy> |
220 | C<async> does. As the coroutine is being reused, stuff like C<on_destroy> |
218 | will not work in the expected way, unless you call terminate or cancel, |
221 | will not work in the expected way, unless you call terminate or cancel, |
219 | which somehow defeats the purpose of pooling. |
222 | which somehow defeats the purpose of pooling. |
220 | |
223 | |
221 | The priority will be reset to C<0> after each job, otherwise the coroutine |
224 | The priority will be reset to C<0> after each job, tracing will be |
222 | will be re-used "as-is". |
225 | disabled, the description will be reset and the default output filehandle |
|
|
226 | gets restored, so you can change alkl these. Otherwise the coroutine will |
|
|
227 | be re-used "as-is": most notably if you change other per-coroutine global |
|
|
228 | stuff such as C<$/> you need to revert that change, which is most simply |
|
|
229 | done by using local as in C< local $/ >. |
223 | |
230 | |
224 | The pool size is limited to 8 idle coroutines (this can be adjusted by |
231 | The pool size is limited to 8 idle coroutines (this can be adjusted by |
225 | changing $Coro::POOL_SIZE), and there can be as many non-idle coros as |
232 | changing $Coro::POOL_SIZE), and there can be as many non-idle coros as |
226 | required. |
233 | required. |
227 | |
234 | |
… | |
… | |
344 | Create a new coroutine and return it. When the sub returns the coroutine |
351 | Create a new coroutine and return it. When the sub returns the coroutine |
345 | automatically terminates as if C<terminate> with the returned values were |
352 | automatically terminates as if C<terminate> with the returned values were |
346 | called. To make the coroutine run you must first put it into the ready queue |
353 | called. To make the coroutine run you must first put it into the ready queue |
347 | by calling the ready method. |
354 | by calling the ready method. |
348 | |
355 | |
349 | See C<async> for additional discussion. |
356 | See C<async> and C<Coro::State::new> for additional info about the |
|
|
357 | coroutine environment. |
350 | |
358 | |
351 | =cut |
359 | =cut |
352 | |
360 | |
353 | sub _run_coro { |
361 | sub _run_coro { |
354 | terminate &{+shift}; |
362 | terminate &{+shift}; |
… | |
… | |
589 | to allow per-thread schedulers, but Coro::State does not yet allow |
597 | to allow per-thread schedulers, but Coro::State does not yet allow |
590 | this). |
598 | this). |
591 | |
599 | |
592 | =head1 SEE ALSO |
600 | =head1 SEE ALSO |
593 | |
601 | |
594 | Support/Utility: L<Coro::Cont>, L<Coro::Specific>, L<Coro::State>, L<Coro::Util>. |
602 | Support/Utility: L<Coro::Specific>, L<Coro::State>, L<Coro::Util>. |
595 | |
603 | |
596 | Locking/IPC: L<Coro::Signal>, L<Coro::Channel>, L<Coro::Semaphore>, L<Coro::SemaphoreSet>, L<Coro::RWLock>. |
604 | Locking/IPC: L<Coro::Signal>, L<Coro::Channel>, L<Coro::Semaphore>, L<Coro::SemaphoreSet>, L<Coro::RWLock>. |
597 | |
605 | |
598 | Event/IO: L<Coro::Timer>, L<Coro::Event>, L<Coro::Handle>, L<Coro::Socket>, L<Coro::Select>. |
606 | Event/IO: L<Coro::Timer>, L<Coro::Event>, L<Coro::Handle>, L<Coro::Socket>, L<Coro::Select>. |
599 | |
607 | |