Run serially executes the submitted callback. Blocking tasks must be cancelable by context.
(ctx context.Context, t func(context.Context))
| 78 | // Run serially executes the submitted callback. |
| 79 | // Blocking tasks must be cancelable by context. |
| 80 | func (l *Loop) Run(ctx context.Context, t func(context.Context)) error { |
| 81 | if err := l.Err(); err != nil { |
| 82 | return err |
| 83 | } |
| 84 | done := make(chan struct{}) |
| 85 | select { |
| 86 | case <-ctx.Done(): |
| 87 | return ctx.Err() |
| 88 | case <-l.done: |
| 89 | return ErrClosed |
| 90 | case l.tasks <- task{t, done}: |
| 91 | <-done |
| 92 | |
| 93 | return nil |
| 94 | } |
| 95 | } |
| 96 | |
| 97 | // The following methods implement context.Context for TaskLoop |
| 98 |