Wait signals to the stream that all tasks have been submitted. Wait will not return until all tasks and callbacks have been run.
()
| 89 | // Wait signals to the stream that all tasks have been submitted. Wait will |
| 90 | // not return until all tasks and callbacks have been run. |
| 91 | func (s *Stream) Wait() { |
| 92 | s.init() |
| 93 | |
| 94 | // Defer the callbacker cleanup so that it occurs even in the case |
| 95 | // that one of the tasks panics and is propagated up by s.pool.Wait(). |
| 96 | defer func() { |
| 97 | close(s.queue) |
| 98 | s.callbackerHandle.Wait() |
| 99 | }() |
| 100 | |
| 101 | // Wait for all the workers to exit. |
| 102 | s.pool.Wait() |
| 103 | } |
| 104 | |
| 105 | func (s *Stream) WithMaxGoroutines(n int) *Stream { |
| 106 | s.pool.WithMaxGoroutines(n) |