--- cvsroot/Coro/README 2008/05/10 22:32:40 1.14 +++ cvsroot/Coro/README 2008/11/05 15:38:10 1.17 @@ -16,6 +16,7 @@ cede; # and again # use locking + use Coro::Semaphore; my $lock = new Coro::Semaphore; my $locked; @@ -55,8 +56,8 @@ This variable stores the coroutine object that represents the main program. While you cna "ready" it and do most other things you can do to coroutines, it is mainly useful to compare again - $Coro::current, to see wether you are running in the main program or - not. + $Coro::current, to see whether you are running in the main program + or not. $Coro::current The coroutine object representing the current coroutine (the last @@ -128,7 +129,7 @@ can be good or bad :). On the plus side, this function is faster than creating (and - destroying) a completely new coroutine, so if you need a lot of + destroying) a completly new coroutine, so if you need a lot of generic coroutines in quick successsion, use "async_pool", not "async". @@ -143,13 +144,12 @@ disabled, the description will be reset and the default output filehandle gets restored, so you can change all these. Otherwise the coroutine will be re-used "as-is": most notably if you change other - per-coroutine global stuff such as $/ you *must needs* to revert - that change, which is most simply done by using local as in: " local - $/ ". - - The pool size is limited to 8 idle coroutines (this can be adjusted - by changing $Coro::POOL_SIZE), and there can be as many non-idle - coros as required. + per-coroutine global stuff such as $/ you *must needs* revert that + change, which is most simply done by using local as in: "local $/". + + The idle pool size is limited to 8 idle coroutines (this can be + adjusted by changing $Coro::POOL_SIZE), but there can be as many + non-idle coros as required. If you are concerned about pooled coroutines growing a lot because a single "async_pool" used a lot of stackspace you can e.g. @@ -179,7 +179,7 @@ current coroutine in a variable, then arrange for some callback of yours to call "->ready" on that once some event happens, and last you call "schedule" to put yourself to sleep. Note that a lot of - things can wake your coroutine up, so you need to check wether the + things can wake your coroutine up, so you need to check whether the event indeed happened, e.g. by storing the status in a variable. The canonical way to wait on external events is this: @@ -225,7 +225,7 @@ as usually only one of them should inherit the running coroutines. Note that while this will try to free some of the main programs - resources, you cnanot free all of them, so if a coroutine that is + resources, you cannot free all of them, so if a coroutine that is not the main program calls this function, there will be some one-time resource leak. @@ -253,13 +253,31 @@ earlier have been resumed. $is_ready = $coroutine->is_ready - Return wether the coroutine is currently the ready queue or not, + Return whether the coroutine is currently the ready queue or not, $coroutine->cancel (arg...) Terminates the given coroutine and makes it return the given arguments as status (default: the empty list). Never returns if the coroutine is the current coroutine. + $coroutine->throw ([$scalar]) + If $throw is specified and defined, it will be thrown as an + exception inside the coroutine at the next convenient point in time + (usually after it gains control at the next schedule/transfer/cede). + Otherwise clears the exception object. + + The exception object will be thrown "as is" with the specified + scalar in $@, i.e. if it is a string, no line number or newline will + be appended (unlike with "die"). + + This can be used as a softer means than "cancel" to ask a coroutine + to end itself, although there is no guarantee that the exception + will lead to termination, and if the exception isn't caught it might + well end the whole program. + + You might also think of "throw" as being the moral equivalent of + "kill"ing a coroutine with a signal (in this case, a scalar). + $coroutine->join Wait until the coroutine terminates and return any values given to the "terminate" or "cancel" functions. "join" can be called @@ -306,21 +324,6 @@ This method simply sets the "$coroutine->{desc}" member to the given string. You can modify this member directly if you wish. - $coroutine->throw ([$scalar]) - If $throw is specified and defined, it will be thrown as an - exception inside the coroutine at the next convinient point in time - (usually after it gains control at the next schedule/transfer/cede). - Otherwise clears the exception object. - - The exception object will be thrown "as is" with the specified - scalar in $@, i.e. if it is a string, no line number or newline will - be appended (unlike with "die"). - - This can be used as a softer means than "cancel" to ask a coroutine - to end itself, although there is no guarentee that the exception - will lead to termination, and if the exception isn't caught it might - well end the whole program. - GLOBAL FUNCTIONS Coro::nready Returns the number of coroutines that are currently in the ready