readLoop streams input events to the program until ctx is done or reading fails. It takes the per-run state it uses as arguments rather than reading it from p: the loop can outlive [Program.shutdown], see [Program.shutdownInput], and must not race with a later run replacing it.
(ctx context.Context, scanner *uv.TerminalReader, done chan struct{}, errs chan error)
| 101 | // it from p: the loop can outlive [Program.shutdown], see |
| 102 | // [Program.shutdownInput], and must not race with a later run replacing it. |
| 103 | func (p *Program) readLoop(ctx context.Context, scanner *uv.TerminalReader, done chan struct{}, errs chan error) { |
| 104 | defer close(done) |
| 105 | |
| 106 | if err := scanner.StreamEvents(ctx, p.msgs); err != nil { |
| 107 | select { |
| 108 | case <-ctx.Done(): |
| 109 | return |
| 110 | case errs <- err: |
| 111 | } |
| 112 | } |
| 113 | } |
| 114 | |
| 115 | const inputReadLoopTimeout = 500 * time.Millisecond |
| 116 |