… | |
… | |
49 | |
49 | |
50 | use Carp; |
50 | use Carp; |
51 | no warnings; |
51 | no warnings; |
52 | |
52 | |
53 | use Coro; |
53 | use Coro; |
|
|
54 | use Coro::Timer; |
54 | use Event qw(loop unloop); # we are re-exporting this, cooool! |
55 | use Event qw(loop unloop); # we are re-exporting this, cooool! |
55 | |
56 | |
56 | use XSLoader; |
57 | use XSLoader; |
57 | |
58 | |
58 | use base Exporter::; |
59 | use base Exporter::; |
59 | |
60 | |
60 | our @EXPORT = qw(loop unloop sweep reschedule); |
61 | our @EXPORT = qw(loop unloop sweep); |
61 | |
62 | |
62 | BEGIN { |
63 | BEGIN { |
63 | our $VERSION = 1.9; |
64 | our $VERSION = 1.9; |
64 | |
65 | |
65 | local $^W = 0; # avoid redefine warning for Coro::ready; |
66 | local $^W = 0; # avoid redefine warning for Coro::ready; |
… | |
… | |
122 | } |
123 | } |
123 | |
124 | |
124 | # double calls to avoid stack-cloning ;() |
125 | # double calls to avoid stack-cloning ;() |
125 | # is about 10% slower, though. |
126 | # is about 10% slower, though. |
126 | sub next($) { |
127 | sub next($) { |
127 | &Coro::schedule if &_next; $_[0]; |
128 | &Coro::schedule while &_next; |
|
|
129 | |
|
|
130 | $_[0] |
128 | } |
131 | } |
129 | |
132 | |
130 | sub Coro::Event::w { $_[0] } |
133 | sub Coro::Event::w { $_[0] } |
131 | sub Coro::Event::prio { $_[0]{Coro::Event}[3] } |
134 | sub Coro::Event::prio { $_[0]{Coro::Event}[3] } |
132 | sub Coro::Event::hits { $_[0]{Coro::Event}[4] } |
135 | sub Coro::Event::hits { $_[0]{Coro::Event}[4] } |
… | |
… | |
159 | |
162 | |
160 | Same as Event::unloop (provided here for your convinience only). |
163 | Same as Event::unloop (provided here for your convinience only). |
161 | |
164 | |
162 | =cut |
165 | =cut |
163 | |
166 | |
164 | $Coro::idle = new Coro sub { |
167 | $Coro::idle = \&Event::one_event; # inefficient |
165 | while () { |
|
|
166 | Event::one_event; # inefficient |
|
|
167 | Coro::schedule; |
|
|
168 | } |
|
|
169 | }; |
|
|
170 | |
|
|
171 | # provide hooks for Coro::Timer |
|
|
172 | |
|
|
173 | package Coro::Timer; |
|
|
174 | |
|
|
175 | unless ($override) { |
|
|
176 | $override = 1; |
|
|
177 | *_new_timer = sub { |
|
|
178 | Event->timer(at => $_[0], cb => $_[1]); |
|
|
179 | }; |
|
|
180 | } |
|
|
181 | |
168 | |
182 | 1; |
169 | 1; |
183 | |
170 | |
184 | =back |
171 | =back |
185 | |
172 | |