… | |
… | |
64 | |
64 | |
65 | =item $q->get |
65 | =item $q->get |
66 | |
66 | |
67 | Return the next element from the queue, waiting if necessary. |
67 | Return the next element from the queue, waiting if necessary. |
68 | |
68 | |
|
|
69 | =item $q->timed_get ($timeout) |
|
|
70 | |
|
|
71 | Return the next element from the queue, waiting up to C<$timeout> seconds |
|
|
72 | if necessary. If no element arrives within the given time an empty list |
|
|
73 | will be returned. |
|
|
74 | |
69 | =cut |
75 | =cut |
70 | |
76 | |
71 | sub get { |
77 | sub 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 | |
|
|
88 | sub 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 | |