Write implements io.Writer. It is safe for concurrent use.
(p []byte)
| 36 | |
| 37 | // Write implements io.Writer. It is safe for concurrent use. |
| 38 | func (wb *WaitBuffer) Write(p []byte) (int, error) { |
| 39 | wb.mu.Lock() |
| 40 | defer wb.mu.Unlock() |
| 41 | |
| 42 | n, err := wb.buf.Write(p) |
| 43 | s := wb.buf.String() |
| 44 | for _, w := range wb.waiters { |
| 45 | if w.cond(s) { |
| 46 | w.once.Do(func() { close(w.ch) }) |
| 47 | } |
| 48 | } |
| 49 | return n, err |
| 50 | } |
| 51 | |
| 52 | // WaitFor blocks until the accumulated output contains signal or |
| 53 | // ctx expires. Returns nil on match, ctx.Err() on timeout. |