Tick signals that an event has occurred by closing the channel and incrementing cursor.
()
| 25 | |
| 26 | // Tick signals that an event has occurred by closing the channel and incrementing cursor. |
| 27 | func (t *Cond) Tick() { |
| 28 | t.mu.Lock() |
| 29 | defer t.mu.Unlock() |
| 30 | |
| 31 | if t.ch != nil { |
| 32 | t.cursor.Add(1) // Increment FIRST so waiters see new cursor when they wake |
| 33 | close(t.ch) // Then close channel to wake waiters |
| 34 | t.ch = make(condCh) // Create new channel for next Tick |
| 35 | } |
| 36 | } |
| 37 | |
| 38 | // Cursor returns the current cursor value. |
| 39 | // Capture this before checking your condition, then pass it to Wait(). |