… | |
… | |
87 | |
87 | |
88 | =item $q->shutdown |
88 | =item $q->shutdown |
89 | |
89 | |
90 | Shuts down the Channel by pushing a virtual end marker onto it: This |
90 | Shuts down the Channel by pushing a virtual end marker onto it: This |
91 | changes the behaviour of the Channel when it becomes or is empty to return |
91 | changes the behaviour of the Channel when it becomes or is empty to return |
92 | C<undef>, almost as if infinitely many C<undef> elements have been put |
92 | C<undef>, almost as if infinitely many C<undef> elements had been put |
93 | into the queue. |
93 | into the queue. |
94 | |
94 | |
95 | Specifically, this function wakes up any pending C<get> calls and lets |
95 | Specifically, this function wakes up any pending C<get> calls and lets |
96 | them return C<undef>, the same on future C<get> calls. C<size> will return |
96 | them return C<undef>, the same on future C<get> calls. C<size> will return |
97 | the real number of stored elements, though. |
97 | the real number of stored elements, though. |
… | |
… | |
104 | This method is useful to signal the end of data to any consumers, quite |
104 | This method is useful to signal the end of data to any consumers, quite |
105 | similar to an end of stream on e.g. a tcp socket: You have one or more |
105 | similar to an end of stream on e.g. a tcp socket: You have one or more |
106 | producers that C<put> data into the Channel and one or more consumers who |
106 | producers that C<put> data into the Channel and one or more consumers who |
107 | C<get> them. When all producers have finished producing data, a call to |
107 | C<get> them. When all producers have finished producing data, a call to |
108 | C<shutdown> signals this fact to any consumers. |
108 | C<shutdown> signals this fact to any consumers. |
|
|
109 | |
|
|
110 | A common implementation uses one or more threads that C<get> from |
|
|
111 | a channel until it returns C<undef>. To clean everything up, first |
|
|
112 | C<shutdown> the channel, then C<join> the threads. |
109 | |
113 | |
110 | =cut |
114 | =cut |
111 | |
115 | |
112 | sub shutdown { |
116 | sub shutdown { |
113 | Coro::Semaphore::adjust $_[0][SGET], 1_000_000_000; |
117 | Coro::Semaphore::adjust $_[0][SGET], 1_000_000_000; |