WaitUntilEmpty waits until the LogSender's queues are empty or the given context expires.
(ctx context.Context)
| 490 | |
| 491 | // WaitUntilEmpty waits until the LogSender's queues are empty or the given context expires. |
| 492 | func (l *LogSender) WaitUntilEmpty(ctx context.Context) error { |
| 493 | ctxDone := false |
| 494 | nevermind := make(chan struct{}) |
| 495 | defer close(nevermind) |
| 496 | go func() { |
| 497 | select { |
| 498 | case <-ctx.Done(): |
| 499 | l.L.Lock() |
| 500 | defer l.L.Unlock() |
| 501 | ctxDone = true |
| 502 | l.Broadcast() |
| 503 | return |
| 504 | case <-nevermind: |
| 505 | return |
| 506 | } |
| 507 | }() |
| 508 | l.L.Lock() |
| 509 | defer l.L.Unlock() |
| 510 | for len(l.queues) != 0 && !ctxDone { |
| 511 | l.Wait() |
| 512 | } |
| 513 | if len(l.queues) == 0 { |
| 514 | return nil |
| 515 | } |
| 516 | return ctx.Err() |
| 517 | } |
| 518 | |
| 519 | type ScriptLogger struct { |
| 520 | sender *LogSender |