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

Comparing Coro/Coro/Channel.pm (file contents):
Revision 1.46 by root, Sun Aug 19 08:46:46 2007 UTC vs.
Revision 1.47 by root, Wed Feb 13 15:40:33 2008 UTC

64 64
65=item $q->get 65=item $q->get
66 66
67Return the next element from the queue, waiting if necessary. 67Return the next element from the queue, waiting if necessary.
68 68
69=item $q->timed_get ($timeout)
70
71Return the next element from the queue, waiting up to C<$timeout> seconds
72if necessary. If no element arrives within the given time an empty list
73will be returned.
74
69=cut 75=cut
70 76
71sub get { 77sub get {
72 (pop @{$_[0][3]})->ready if @{$_[0][3]}; 78 (pop @{$_[0][3]})->ready if @{$_[0][3]};
73 79
74 while (!@{$_[0][0]}) { 80 while (!@{$_[0][0]}) {
75 push @{$_[0][1]}, $Coro::current; 81 push @{$_[0][1]}, $Coro::current;
76 &Coro::schedule; 82 &Coro::schedule;
83 }
84
85 shift @{$_[0][0]}
86}
87
88sub timed_get {
89 require Coro::Timer;
90 my $timeout = Coro::Timer::timeout ($_[0]);
91
92 (pop @{$_[0][3]})->ready if @{$_[0][3]};
93
94 while (!@{$_[0][0]}) {
95 push @{$_[0][1]}, $Coro::current;
96 &Coro::schedule;
97 return if $timeout;
77 } 98 }
78 99
79 shift @{$_[0][0]} 100 shift @{$_[0][0]}
80} 101}
81 102

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines