This method always returns `nil, nil`.
(ctx context.Context, _ Env, r io.ReadCloser)
| 28 | |
| 29 | // This method always returns `nil, nil`. |
| 30 | func (s *ioCopier) Start(ctx context.Context, _ Env, r io.ReadCloser) (io.ReadCloser, error) { |
| 31 | go func() { |
| 32 | _, err := io.Copy(s.w, r) |
| 33 | // We don't consider `ErrClosed` an error (FIXME: is this |
| 34 | // correct?): |
| 35 | if err != nil && !errors.Is(err, os.ErrClosed) { |
| 36 | s.err = err |
| 37 | } |
| 38 | if err := r.Close(); err != nil && s.err == nil { |
| 39 | s.err = err |
| 40 | } |
| 41 | if err := s.w.Close(); err != nil && s.err == nil { |
| 42 | s.err = err |
| 43 | } |
| 44 | close(s.done) |
| 45 | }() |
| 46 | |
| 47 | // FIXME: if `s.w.Write()` is blocking (e.g., because there is a |
| 48 | // downstream process that is not reading from the other side), |
| 49 | // there's no way to terminate the copy when the context expires. |
| 50 | // This is not too bad, because the `io.Copy()` call will exit by |
| 51 | // itself when its input is closed. |
| 52 | // |
| 53 | // We could, however, be smarter about exiting more quickly if the |
| 54 | // context expires but `s.w.Write()` is not blocking. |
| 55 | |
| 56 | return nil, nil |
| 57 | } |
| 58 | |
| 59 | func (s *ioCopier) Wait() error { |
| 60 | <-s.done |