Next returns the next data point on the wrapped diode. If there is not any new data, it will Wait for set to be called or the context to be done. If the context is done, then nil will be returned.
()
| 61 | // new data, it will Wait for set to be called or the context to be done. |
| 62 | // If the context is done, then nil will be returned. |
| 63 | func (w *Waiter) Next() GenericDataType { |
| 64 | w.mu.Lock() |
| 65 | defer w.mu.Unlock() |
| 66 | |
| 67 | for { |
| 68 | data, ok := w.Diode.TryNext() |
| 69 | if !ok { |
| 70 | if w.isDone() { |
| 71 | return nil |
| 72 | } |
| 73 | |
| 74 | w.c.Wait() |
| 75 | continue |
| 76 | } |
| 77 | return data |
| 78 | } |
| 79 | } |
| 80 | |
| 81 | func (w *Waiter) isDone() bool { |
| 82 | select { |