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

Comparing Coro/Coro.pm (file contents):
Revision 1.56 by pcg, Sat Nov 15 03:53:10 2003 UTC vs.
Revision 1.57 by pcg, Sun Nov 30 22:49:25 2003 UTC

120# this coroutine is necessary because a coroutine 120# this coroutine is necessary because a coroutine
121# cannot destroy itself. 121# cannot destroy itself.
122my @destroy; 122my @destroy;
123my $manager; 123my $manager;
124$manager = new Coro sub { 124$manager = new Coro sub {
125 while() { 125 while () {
126 # by overwriting the state object with the manager we destroy it 126 # by overwriting the state object with the manager we destroy it
127 # while still being able to schedule this coroutine (in case it has 127 # while still being able to schedule this coroutine (in case it has
128 # been readied multiple times. this is harmless since the manager 128 # been readied multiple times. this is harmless since the manager
129 # can be called as many times as neccessary and will always 129 # can be called as many times as neccessary and will always
130 # remove itself from the runqueue 130 # remove itself from the runqueue
157 # create a new coroutine that just prints its arguments 157 # create a new coroutine that just prints its arguments
158 async { 158 async {
159 print "@_\n"; 159 print "@_\n";
160 } 1,2,3,4; 160 } 1,2,3,4;
161 161
162The coderef you submit MUST NOT be a closure that refers to variables
163in an outer scope. This does NOT work. Pass arguments into it instead.
164
165=cut 162=cut
166 163
167sub async(&@) { 164sub async(&@) {
168 my $pid = new Coro @_; 165 my $pid = new Coro @_;
169 $manager->ready; # this ensures that the stack is cloned from the manager 166 $manager->ready; # this ensures that the stack is cloned from the manager

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines