… | |
… | |
47 | =item $s->wait |
47 | =item $s->wait |
48 | |
48 | |
49 | Wait for the signal to occur. Returns immediately if the signal has been |
49 | Wait for the signal to occur. Returns immediately if the signal has been |
50 | sent before. |
50 | sent before. |
51 | |
51 | |
52 | Signals are not reliable, so this function might return |
52 | Signals are not reliable: this function might return spuriously without |
53 | spuriously. Always test for the condition you are waiting on. |
53 | the signal being sent. This means you must always test for the condition |
|
|
54 | you are waiting for. |
|
|
55 | |
|
|
56 | (If this is a real problem for you the situation might be remedied in a |
|
|
57 | future version). |
54 | |
58 | |
55 | =item $status = $s->timed_wait ($timeout) |
59 | =item $status = $s->timed_wait ($timeout) |
56 | |
60 | |
57 | Like C<wait>, but returns false if no signal happens within $timeout |
61 | Like C<wait>, but returns false if no signal happens within $timeout |
58 | seconds, otherwise true. |
62 | seconds, otherwise true. |
59 | |
63 | |
60 | See C<wait> for reliability concerns. |
64 | See C<wait> for some reliability concerns. |
61 | |
65 | |
62 | =cut |
66 | =cut |
63 | |
67 | |
64 | sub wait { |
68 | sub wait { |
65 | while (!$_[0][0]) { |
69 | unless (delete $_[0][0]) { |
66 | push @{$_[0][1]}, $Coro::current; |
70 | push @{$_[0][1]}, $Coro::current; |
67 | &Coro::schedule; |
71 | &Coro::schedule; |
68 | } |
72 | } |
69 | $_[0][0] = 0; |
|
|
70 | } |
73 | } |
71 | |
74 | |
72 | sub timed_wait { |
75 | sub timed_wait { |
73 | require Coro::Timer; |
76 | require Coro::Timer; |
74 | my $timeout = Coro::Timer::timeout($_[1]); |
77 | my $timeout = Coro::Timer::timeout($_[1]); |
75 | |
78 | |
76 | while (!$_[0][0]) { |
79 | unless (delete $_[0][0]) { |
77 | push @{$_[0][1]}, $Coro::current; |
80 | push @{$_[0][1]}, $Coro::current; |
78 | &Coro::schedule; |
81 | &Coro::schedule; |
79 | |
82 | |
80 | return 0 if $timeout; |
83 | return 0 if $timeout; |
81 | } |
84 | } |
82 | |
|
|
83 | $_[0][0] = 0; |
|
|
84 | |
85 | |
85 | 1 |
86 | 1 |
86 | } |
87 | } |
87 | |
88 | |
88 | =item $s->send |
89 | =item $s->send |