… | |
… | |
118 | # this coroutine is necessary because a coroutine |
118 | # this coroutine is necessary because a coroutine |
119 | # cannot destroy itself. |
119 | # cannot destroy itself. |
120 | my @destroy; |
120 | my @destroy; |
121 | my $manager = new Coro sub { |
121 | my $manager = new Coro sub { |
122 | while() { |
122 | while() { |
123 | delete ((pop @destroy)->{_coro_state}) while @destroy; |
123 | # by overwriting the state object with the manager we destroy it |
|
|
124 | # while still being able to schedule this coroutine (in case it has |
|
|
125 | # been readied multiple times. this is harmless since the manager |
|
|
126 | # can be called as many times as neccessary and will always |
|
|
127 | # remove itself from the runqueue |
|
|
128 | (pop @destroy)->{_coro_state} = $manager->{_coro_state} while @destroy; |
124 | &schedule; |
129 | &schedule; |
125 | } |
130 | } |
126 | }; |
131 | }; |
127 | |
132 | |
128 | # static methods. not really. |
133 | # static methods. not really. |