Flush will send the currently written data to output and block until everything has been written. This should only be used on rare occasions where pushing the currently queued data is critical.
()
| 545 | // and block until everything has been written. |
| 546 | // This should only be used on rare occasions where pushing the currently queued data is critical. |
| 547 | func (e *Encoder) Flush() error { |
| 548 | s := &e.state |
| 549 | if e.o.concurrentBlocks { |
| 550 | return e.flushJobs() |
| 551 | } |
| 552 | if len(s.filling) > 0 { |
| 553 | err := e.nextBlock(false) |
| 554 | if err != nil { |
| 555 | if errors.Is(s.err, ErrEncoderClosed) { |
| 556 | return nil |
| 557 | } |
| 558 | return err |
| 559 | } |
| 560 | } |
| 561 | s.wg.Wait() |
| 562 | s.wWg.Wait() |
| 563 | if s.err != nil { |
| 564 | if errors.Is(s.err, ErrEncoderClosed) { |
| 565 | return nil |
| 566 | } |
| 567 | return s.err |
| 568 | } |
| 569 | return s.writeErr |
| 570 | } |
| 571 | |
| 572 | func (e *Encoder) flushJobs() error { |
| 573 | js := &e.state.jobs |