… | |
… | |
133 | }; |
133 | }; |
134 | |
134 | |
135 | # this coroutine is necessary because a coroutine |
135 | # this coroutine is necessary because a coroutine |
136 | # cannot destroy itself. |
136 | # cannot destroy itself. |
137 | my @destroy; |
137 | my @destroy; |
138 | my $manager; |
|
|
139 | $manager = new Coro sub { |
138 | my $manager; $manager = new Coro sub { |
140 | while () { |
139 | while () { |
141 | # by overwriting the state object with the manager we destroy it |
140 | # by overwriting the state object with the manager we destroy it |
142 | # while still being able to schedule this coroutine (in case it has |
141 | # while still being able to schedule this coroutine (in case it has |
143 | # been readied multiple times. this is harmless since the manager |
142 | # been readied multiple times. this is harmless since the manager |
144 | # can be called as many times as neccessary and will always |
143 | # can be called as many times as neccessary and will always |
… | |
… | |
234 | by calling the ready method. |
233 | by calling the ready method. |
235 | |
234 | |
236 | =cut |
235 | =cut |
237 | |
236 | |
238 | sub _new_coro { |
237 | sub _new_coro { |
239 | $current->_clear_idle_sp; # set the idle sp on the following cede |
|
|
240 | _set_cede_self; # ensures that cede cede's us first |
|
|
241 | cede; |
|
|
242 | terminate &{+shift}; |
238 | terminate &{+shift}; |
243 | } |
239 | } |
244 | |
240 | |
245 | sub new { |
241 | sub new { |
246 | my $class = shift; |
242 | my $class = shift; |