(f func())
| 22 | } |
| 23 | |
| 24 | func (q *ExecQueue) Add(f func()) { |
| 25 | q.mu.Lock() |
| 26 | defer q.mu.Unlock() |
| 27 | if q.closed { |
| 28 | return |
| 29 | } |
| 30 | q.initCtxLocked() |
| 31 | if q.inFlight { |
| 32 | q.queue = append(q.queue, f) |
| 33 | } else { |
| 34 | q.inFlight = true |
| 35 | go q.run(f) |
| 36 | } |
| 37 | } |
| 38 | |
| 39 | // RunSync waits for the queue to be drained and then synchronously runs f. |
| 40 | // It returns an error if the queue is closed before f is run or ctx expires. |