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

Comparing Coro/Coro/Timer.pm (file contents):
Revision 1.52 by root, Sat Nov 8 16:46:32 2008 UTC vs.
Revision 1.57 by root, Thu Nov 20 14:57:45 2008 UTC

28use AnyEvent (); 28use AnyEvent ();
29 29
30use Coro (); 30use Coro ();
31use Coro::AnyEvent (); 31use Coro::AnyEvent ();
32 32
33$VERSION = 4.9; 33$VERSION = "5.0";
34@EXPORT_OK = qw(timeout sleep); 34@EXPORT_OK = qw(timeout sleep);
35 35
36=item $flag = timeout $seconds; 36=item $flag = timeout $seconds;
37 37
38This function will wake up the current coroutine after $seconds 38This function will wake up the current coroutine after $seconds
80and, most important, without blocking other coroutines. 80and, most important, without blocking other coroutines.
81 81
82=cut 82=cut
83 83
84sub sleep { 84sub sleep {
85 my $current = $Coro::current;
86
87 my $timer = AnyEvent->timer (after => $_[0], cb => sub { 85 my $timer = AnyEvent->timer (after => $_[0], cb => Coro::rouse_cb);
88 $current->ready; 86 Coro::rouse_wait;
89 undef $current;
90 });
91
92 do { &Coro::schedule } while $current;
93} 87}
94 88
951; 891;
96 90
97=back 91=back

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines