Wait until underlying state is the desired one, returning whether it had to wait or not.
(ctx context.Context, desired interface{})
| 94 | |
| 95 | // Wait until underlying state is the desired one, returning whether it had to wait or not. |
| 96 | func (t *stateTracker) Wait(ctx context.Context, desired interface{}) bool { |
| 97 | t.cond.L.Lock() |
| 98 | defer t.cond.L.Unlock() |
| 99 | |
| 100 | waited := false |
| 101 | |
| 102 | if t.value != desired { |
| 103 | waited = true |
| 104 | log(ctx, nil). |
| 105 | WithField("current", t.value). |
| 106 | WithField("desired", desired). |
| 107 | Info("waiting for a state change") |
| 108 | } |
| 109 | |
| 110 | // Can be broadcasted many times, wait for the right desired |
| 111 | for t.value != desired { |
| 112 | t.cond.Wait() |
| 113 | } |
| 114 | |
| 115 | return waited |
| 116 | } |
| 117 | |
| 118 | func (t *stateTracker) NewListener() <-chan *Notification { |
| 119 | t.cond.L.Lock() |