… | |
… | |
66 | async { ... } [@args...] |
66 | async { ... } [@args...] |
67 | Create a new asynchronous coroutine and return it's coroutine object |
67 | Create a new asynchronous coroutine and return it's coroutine object |
68 | (usually unused). When the sub returns the new coroutine is |
68 | (usually unused). When the sub returns the new coroutine is |
69 | automatically terminated. |
69 | automatically terminated. |
70 | |
70 | |
71 | Calling "exit" in a coroutine will not work correctly, so do not do |
71 | Calling "exit" in a coroutine will do the same as calling exit |
72 | that. |
72 | outside the coroutine. Likewise, when the coroutine dies, the |
73 | |
73 | program will exit, just as it would in the main program. |
74 | When the coroutine dies, the program will exit, just as in the main |
|
|
75 | program. |
|
|
76 | |
74 | |
77 | # create a new coroutine that just prints its arguments |
75 | # create a new coroutine that just prints its arguments |
78 | async { |
76 | async { |
79 | print "@_\n"; |
77 | print "@_\n"; |
80 | } 1,2,3,4; |
78 | } 1,2,3,4; |
… | |
… | |
155 | Create a new coroutine and return it. When the sub returns the |
153 | Create a new coroutine and return it. When the sub returns the |
156 | coroutine automatically terminates as if "terminate" with the |
154 | coroutine automatically terminates as if "terminate" with the |
157 | returned values were called. To make the coroutine run you must |
155 | returned values were called. To make the coroutine run you must |
158 | first put it into the ready queue by calling the ready method. |
156 | first put it into the ready queue by calling the ready method. |
159 | |
157 | |
160 | Calling "exit" in a coroutine will not work correctly, so do not do |
158 | See "async" for additional discussion. |
161 | that. |
|
|
162 | |
159 | |
163 | $success = $coroutine->ready |
160 | $success = $coroutine->ready |
164 | Put the given coroutine into the ready queue (according to it's |
161 | Put the given coroutine into the ready queue (according to it's |
165 | priority) and return true. If the coroutine is already in the ready |
162 | priority) and return true. If the coroutine is already in the ready |
166 | queue, do nothing and return false. |
163 | queue, do nothing and return false. |
… | |
… | |
222 | have no effect, and "schedule" would cause a deadlock unless there |
219 | have no effect, and "schedule" would cause a deadlock unless there |
223 | is an idle handler that wakes up some coroutines. |
220 | is an idle handler that wakes up some coroutines. |
224 | |
221 | |
225 | my $guard = Coro::guard { ... } |
222 | my $guard = Coro::guard { ... } |
226 | This creates and returns a guard object. Nothing happens until the |
223 | This creates and returns a guard object. Nothing happens until the |
227 | objetc gets destroyed, in which case the codeblock given as argument |
224 | object gets destroyed, in which case the codeblock given as argument |
228 | will be executed. This is useful to free locks or other resources in |
225 | will be executed. This is useful to free locks or other resources in |
229 | case of a runtime error or when the coroutine gets canceled, as in |
226 | case of a runtime error or when the coroutine gets canceled, as in |
230 | both cases the guard block will be executed. The guard object |
227 | both cases the guard block will be executed. The guard object |
231 | supports only one method, "->cancel", which will keep the codeblock |
228 | supports only one method, "->cancel", which will keep the codeblock |
232 | from being executed. |
229 | from being executed. |