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

Comparing Coro/Event/Event.pm (file contents):
Revision 1.31 by root, Mon Dec 12 17:49:07 2005 UTC vs.
Revision 1.41 by root, Fri Dec 1 02:17:37 2006 UTC

32function - it will be managed by this module. 32function - it will be managed by this module.
33 33
34Your application should just create all necessary coroutines and then call 34Your application should just create all necessary coroutines and then call
35Coro::Event::loop. 35Coro::Event::loop.
36 36
37Please note that even programs or modules (such as
38L<Coro::Handle|Coro::Handle>) that use "traditional"
39event-based/continuation style will run more efficient with this module
40then when using only Event.
41
37=over 4 42=over 4
38 43
39=cut 44=cut
40 45
41package Coro::Event; 46package Coro::Event;
44 49
45use Carp; 50use Carp;
46no warnings; 51no warnings;
47 52
48use Coro; 53use Coro;
54use Coro::Timer;
49use Event qw(loop unloop); # we are re-exporting this, cooool! 55use Event qw(loop unloop); # we are re-exporting this, cooool!
50 56
51use XSLoader; 57use XSLoader;
52 58
53use base Exporter::; 59use base Exporter::;
54 60
55our @EXPORT = qw(loop unloop sweep reschedule); 61our @EXPORT = qw(loop unloop sweep);
56 62
57BEGIN { 63BEGIN {
58 our $VERSION = 1.51; 64 our $VERSION = 1.9;
59 65
60 local $^W = 0; # avoid redefine warning for Coro::ready; 66 local $^W = 0; # avoid redefine warning for Coro::ready;
61 XSLoader::load __PACKAGE__, $VERSION; 67 XSLoader::load __PACKAGE__, $VERSION;
62} 68}
63 69
117} 123}
118 124
119# double calls to avoid stack-cloning ;() 125# double calls to avoid stack-cloning ;()
120# is about 10% slower, though. 126# is about 10% slower, though.
121sub next($) { 127sub next($) {
122 &Coro::schedule if &_next; $_[0]; 128 &Coro::schedule while &_next;
129
130 $_[0]
123} 131}
124 132
125sub Coro::Event::w { $_[0] } 133sub Coro::Event::w { $_[0] }
126sub Coro::Event::prio { $_[0]{Coro::Event}[3] } 134sub Coro::Event::prio { $_[0]{Coro::Event}[3] }
127sub Coro::Event::hits { $_[0]{Coro::Event}[4] } 135sub Coro::Event::hits { $_[0]{Coro::Event}[4] }
148 156
149This is the version of C<loop> you should use instead of C<Event::loop> 157This is the version of C<loop> you should use instead of C<Event::loop>
150when using this module - it will ensure correct scheduling in the presence 158when using this module - it will ensure correct scheduling in the presence
151of events. 159of events.
152 160
153=begin comment
154
155Unlike loop's counterpart it is not an error when no watchers are active -
156loop silently returns in this case, as if unloop(undef) were called.
157
158=end comment
159
160=cut
161
162# no longer do something special - it's done internally now
163
164#sub loop(;$) {
165# #local $Coro::idle = $Coro::current;
166# #Coro::schedule; # become idle task, which is implicitly ready
167# &Event::loop;
168#}
169
170=item unloop([$result]) 161=item unloop([$result])
171 162
172Same as Event::unloop (provided here for your convinience only). 163Same as Event::unloop (provided here for your convinience only).
173 164
174=cut 165=cut
175 166
176$Coro::idle = new Coro sub { 167$Coro::idle = \&Event::one_event; # inefficient
177 while () {
178 Event::one_event; # inefficient
179 Coro::schedule;
180 }
181};
182
183# provide hooks for Coro::Timer
184
185package Coro::Timer;
186
187unless ($override) {
188 $override = 1;
189 *_new_timer = sub {
190 Event->timer(at => $_[0], cb => $_[1]);
191 };
192}
193 168
1941; 1691;
170
171=back
195 172
196=head1 AUTHOR 173=head1 AUTHOR
197 174
198 Marc Lehmann <schmorp@schmorp.de> 175 Marc Lehmann <schmorp@schmorp.de>
199 http://home.schmorp.de/ 176 http://home.schmorp.de/

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines