flush flushes the output buffer to the program output.
()
| 1381 | |
| 1382 | // flush flushes the output buffer to the program output. |
| 1383 | func (p *Program) flush() error { |
| 1384 | p.mu.Lock() |
| 1385 | defer p.mu.Unlock() |
| 1386 | |
| 1387 | if p.outputBuf.Len() == 0 { |
| 1388 | return nil |
| 1389 | } |
| 1390 | if p.logger != nil { |
| 1391 | p.logger.Printf("output: %q", p.outputBuf.String()) |
| 1392 | } |
| 1393 | _, err := p.output.Write(p.outputBuf.Bytes()) |
| 1394 | p.outputBuf.Reset() |
| 1395 | if err != nil { |
| 1396 | return fmt.Errorf("error writing to output: %w", err) |
| 1397 | } |
| 1398 | return nil |
| 1399 | } |
| 1400 | |
| 1401 | // keepWriteErr remembers err as the error to return from [Program.Run] if it |
| 1402 | // is the first error writing to the output. Later errors are dropped so they |
no test coverage detected