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.44 by root, Fri Dec 1 20:49:54 2006 UTC vs.
Revision 1.48 by root, Wed Jan 24 16:24:21 2007 UTC

18 } 18 }
19 } 19 }
20 20
21 loop; 21 loop;
22 22
23 # wait for input on stdin for one second
24
25 Coro::Event::do_io (fd => \*STDIN, timeout => 1) & Event::Watcher::R
26 or die "no input received";
27
23=head1 DESCRIPTION 28=head1 DESCRIPTION
24 29
25This module enables you to create programs using the powerful Event model 30This module enables you to create programs using the powerful Event model
26(and module), while retaining the linear style known from simple or 31(and module), while retaining the linear style known from simple or
27threaded programs. 32threaded programs.
47the current coroutine. 52the current coroutine.
48 53
49While this seems to work superficially, it will eventually cause memory 54While this seems to work superficially, it will eventually cause memory
50corruption. 55corruption.
51 56
57=head1 SEMANTICS
58
59Whenever Event blocks (e.g. in a call to C<one_event>, C<loop> etc.),
60this module cede's to all other coroutines with the same or higher
61priority. When any coroutines of lower priority are ready, it will not
62block but run one of them and then check for events.
63
64The effect is that coroutines with the same or higher priority than
65the blocking coroutine will keep Event from checking for events, while
66coroutines with lower priority are being run, but Event checks for new
67events after every cede.
68
52=head1 FUNCTIONS 69=head1 FUNCTIONS
53 70
54=over 4 71=over 4
55 72
56=cut 73=cut
71use base Exporter::; 88use base Exporter::;
72 89
73our @EXPORT = qw(loop unloop sweep); 90our @EXPORT = qw(loop unloop sweep);
74 91
75BEGIN { 92BEGIN {
76 our $VERSION = 1.9; 93 our $VERSION = '2.1';
77 94
78 local $^W = 0; # avoid redefine warning for Coro::ready; 95 local $^W = 0; # avoid redefine warning for Coro::ready;
79 XSLoader::load __PACKAGE__, $VERSION; 96 XSLoader::load __PACKAGE__, $VERSION;
80} 97}
81 98
90 107
91=cut 108=cut
92 109
93=item $w->next 110=item $w->next
94 111
95Return the next event of the event queue of the watcher. 112Wait for and return the next event of the event queue of the watcher. The
113returned event objects support two methods only: C<hits> and C<got>, both
114of which return integers: the number this watcher was hit for this event,
115and the mask of poll events received.
96 116
97=cut 117=cut
98 118
99=item do_flavour args... 119=item do_flavour args...
100 120
101Create a watcher of the given type and immediately call it's next 121Create a watcher of the given type and immediately call it's next method,
122returning the event.
123
102method. This is less efficient then calling the constructor once and the 124This is less efficient then calling the constructor once and the next
103next method often, but it does save typing sometimes. 125method often, but it does save typing sometimes.
104 126
105=cut 127=cut
106 128
107for my $flavour (qw(idle var timer io signal)) { 129for my $flavour (qw(idle var timer io signal)) {
108 push @EXPORT, "do_$flavour"; 130 push @EXPORT, "do_$flavour";
144 &Coro::schedule while &_next; 166 &Coro::schedule while &_next;
145 167
146 &_event 168 &_event
147} 169}
148 170
171sub Coro::Event::Event::hits { $_[0][3] }
149sub Coro::Event::w { $_[0] } 172sub Coro::Event::Event::got { $_[0][4] }
150sub Coro::Event::prio { $_[0]{Coro::Event}[3] }
151sub Coro::Event::hits { $_[0]{Coro::Event}[4] }
152sub Coro::Event::got { $_[0]{Coro::Event}[5] }
153 173
154=item sweep 174=item sweep
155 175
156Similar to Event::one_event and Event::sweep: The idle task is called once 176Similar to Event::one_event and Event::sweep: The idle task is called once
157(this has the effect of jumping back into the Event loop once to serve new 177(this has the effect of jumping back into the Event loop once to serve new

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines