callbacker is responsible for calling the returned callbacks in the order they were submitted. There is only a single instance of callbacker running.
()
| 119 | // callbacker is responsible for calling the returned callbacks in the order |
| 120 | // they were submitted. There is only a single instance of callbacker running. |
| 121 | func (s *Stream) callbacker() { |
| 122 | var panicCatcher panics.Catcher |
| 123 | defer panicCatcher.Repanic() |
| 124 | |
| 125 | // For every scheduled task, read that tasks channel from the queue. |
| 126 | for callbackCh := range s.queue { |
| 127 | // Wait for the task to complete and get its callback from the channel. |
| 128 | callback := <-callbackCh |
| 129 | |
| 130 | // Execute the callback (with panic protection). |
| 131 | panicCatcher.Try(callback) |
| 132 | |
| 133 | // Return the channel to the pool of unused channels. |
| 134 | putCh(callbackCh) |
| 135 | } |
| 136 | } |
| 137 | |
| 138 | type callbackCh chan func() |
| 139 |