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.33 by root, Fri Nov 24 15:34:33 2006 UTC vs.
Revision 1.34 by root, Fri Dec 1 02:17:37 2006 UTC

44 44
45 sub timed_wait { 45 sub timed_wait {
46 my $timeout = Coro::Timer::timeout 60; 46 my $timeout = Coro::Timer::timeout 60;
47 47
48 while (condition false) { 48 while (condition false) {
49 schedule; # wait until woken up or timeout 49 Coro::schedule; # wait until woken up or timeout
50 return 0 if $timeout; # timed out 50 return 0 if $timeout; # timed out
51 } 51 }
52
52 return 1; # condition satisfied 53 return 1; # condition satisfied
53 } 54 }
54 55
55=cut 56=cut
56 57
82 83
83=cut 84=cut
84 85
85sub sleep { 86sub sleep {
86 my $current = $Coro::current; 87 my $current = $Coro::current;
88
87 my $timer = AnyEvent->timer (after => $_[0], cb => sub { $current->ready }); 89 my $timer = AnyEvent->timer (after => $_[0], cb => sub {
88 Coro::schedule; 90 $current->ready;
91 undef $current;
92 });
93
94 do { &Coro::schedule } while $current;
89} 95}
90 96
91$Coro::idle = sub { 97$Coro::idle = sub {
92 AnyEvent->one_event; 98 AnyEvent->one_event;
93}; 99};

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines