… | |
… | |
26 | |
26 | |
27 | use Coro::State; |
27 | use Coro::State; |
28 | |
28 | |
29 | use base Exporter; |
29 | use base Exporter; |
30 | |
30 | |
31 | $VERSION = 0.04; |
31 | $VERSION = 0.05; |
32 | |
32 | |
33 | @EXPORT = qw(async yield schedule); |
33 | @EXPORT = qw(async yield schedule); |
34 | @EXPORT_OK = qw($current); |
34 | @EXPORT_OK = qw($current); |
35 | |
35 | |
36 | { |
36 | { |
… | |
… | |
113 | terminated. |
113 | terminated. |
114 | |
114 | |
115 | =cut |
115 | =cut |
116 | |
116 | |
117 | sub async(&) { |
117 | sub async(&) { |
118 | (new Coro $_[0])->ready; |
118 | my $pid = new Coro $_[0]; |
|
|
119 | $pid->ready; |
|
|
120 | $pid; |
119 | } |
121 | } |
120 | |
122 | |
121 | =item schedule |
123 | =item schedule |
122 | |
124 | |
123 | Calls the scheduler. Please note that the current process will not be put |
125 | Calls the scheduler. Please note that the current process will not be put |
… | |
… | |
127 | =cut |
129 | =cut |
128 | |
130 | |
129 | my $prev; |
131 | my $prev; |
130 | |
132 | |
131 | sub schedule { |
133 | sub schedule { |
|
|
134 | local @_; |
132 | # should be done using priorities :( |
135 | # should be done using priorities :( |
133 | ($prev, $current) = ($current, shift @ready || $idle); |
136 | ($prev, $current) = ($current, shift @ready || $idle); |
134 | Coro::State::transfer($prev, $current); |
137 | Coro::State::transfer($prev, $current); |
135 | } |
138 | } |
136 | |
139 | |
… | |
… | |
199 | 1; |
202 | 1; |
200 | |
203 | |
201 | =head1 SEE ALSO |
204 | =head1 SEE ALSO |
202 | |
205 | |
203 | L<Coro::Channel>, L<Coro::Cont>, L<Coro::Specific>, L<Coro::Semaphore>, |
206 | L<Coro::Channel>, L<Coro::Cont>, L<Coro::Specific>, L<Coro::Semaphore>, |
204 | L<Coro::Signal>, L<Coro::State>. |
207 | L<Coro::Signal>, L<Coro::State>, L<Coro::Event>. |
205 | |
208 | |
206 | =head1 AUTHOR |
209 | =head1 AUTHOR |
207 | |
210 | |
208 | Marc Lehmann <pcg@goof.com> |
211 | Marc Lehmann <pcg@goof.com> |
209 | http://www.goof.com/pcg/marc/ |
212 | http://www.goof.com/pcg/marc/ |