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.41 by root, Fri Dec 1 02:17:37 2006 UTC vs.
Revision 1.43 by root, Fri Dec 1 19:41:06 2006 UTC

37Please note that even programs or modules (such as 37Please note that even programs or modules (such as
38L<Coro::Handle|Coro::Handle>) that use "traditional" 38L<Coro::Handle|Coro::Handle>) that use "traditional"
39event-based/continuation style will run more efficient with this module 39event-based/continuation style will run more efficient with this module
40then when using only Event. 40then when using only Event.
41 41
42=head1 WARNING
43
44Please note that Event does not support coroutines or threads. That
45means that you B<MUST NOT> block in an event callback. Again: In Event
46callbacks, you I<must never ever> call a Coroutine fucntion that blocks
47the current coroutine.
48
49While this seems to work superficially, it will eventually cause memory
50corruption.
51
52=head1 FUNCTIONS
53
42=over 4 54=over 4
43 55
44=cut 56=cut
45 57
46package Coro::Event; 58package Coro::Event;
47 59
48BEGIN { eval { require warnings } && warnings->unimport ("uninitialized") } 60no warnings;
49 61
50use Carp; 62use Carp;
51no warnings; 63no warnings;
52 64
53use Coro; 65use Coro;
65 77
66 local $^W = 0; # avoid redefine warning for Coro::ready; 78 local $^W = 0; # avoid redefine warning for Coro::ready;
67 XSLoader::load __PACKAGE__, $VERSION; 79 XSLoader::load __PACKAGE__, $VERSION;
68} 80}
69 81
70=item $w = Coro::Event->flavour(args...) 82=item $w = Coro::Event->flavour (args...)
71 83
72Create and return a watcher of the given type. 84Create and return a watcher of the given type.
73 85
74Examples: 86Examples:
75 87
82 94
83Return the next event of the event queue of the watcher. 95Return the next event of the event queue of the watcher.
84 96
85=cut 97=cut
86 98
87=item do_flavour(args...) 99=item do_flavour args...
88 100
89Create a watcher of the given type and immediately call it's next 101Create a watcher of the given type and immediately call it's next
90method. This is less efficient then calling the constructor once and the 102method. This is less efficient then calling the constructor once and the
91next method often, but it does save typing sometimes. 103next method often, but it does save typing sometimes.
92 104
104 116
105 shift eq Coro::Event:: 117 shift eq Coro::Event::
106 or croak "event constructor \"Coro::Event->$flavour\" must be called as a static method"; 118 or croak "event constructor \"Coro::Event->$flavour\" must be called as a static method";
107 119
108 my $w = $new->($class, 120 my $w = $new->($class,
109 desc => $flavour, 121 desc => $flavour,
110 @_, 122 @_,
111 parked => 1, 123 parked => 1,
112 ); 124 );
125
113 _install_std_cb($w, $type); 126 _install_std_cb $w, $type;
114 bless $w, $class; # reblessing due to broken Event 127
128 # reblessing due to Event being broken
129 bless $w, $class
115 }; 130 };
116 *{ $flavour } = $coronew; 131 *{ $flavour } = $coronew;
117 *{"do_$flavour"} = sub { 132 *{"do_$flavour"} = sub {
118 unshift @_, Coro::Event::; 133 unshift @_, Coro::Event::;
119 my $e = (&$coronew)->next; 134 my $e = &$coronew->next;
120 $e->cancel; # $e === $e->w 135 $e->cancel; # $e === $e->w
121 $e; 136 $e
122 }; 137 };
123} 138}
124 139
125# double calls to avoid stack-cloning ;() 140# do schedule in perl to avoid forcign a stack allocation.
126# is about 10% slower, though. 141# this is about 10% slower, though.
127sub next($) { 142sub next($) {
128 &Coro::schedule while &_next; 143 &Coro::schedule while &_next;
129 144
130 $_[0] 145 $_[0]
131} 146}
147into the Event dispatcher. 162into the Event dispatcher.
148 163
149=cut 164=cut
150 165
151sub sweep { 166sub sweep {
152 Event::one_event(0); # for now 167 Event::one_event 0; # for now
153} 168}
154 169
155=item $result = loop([$timeout]) 170=item $result = loop([$timeout])
156 171
157This is the version of C<loop> you should use instead of C<Event::loop> 172This is the version of C<loop> you should use instead of C<Event::loop>

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines