Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ContextReader ¶
type ContextReader struct {
// contains filtered or unexported fields
}
ContextReader wraps an io.Reader to make it respect the given Context. If there is a blocking read, ContextReader will return whenever the context is cancelled (the return values are n=0 and err=ctx.Err() in that case).
Note: this wrapper DOES NOT ACTUALLY cancel the underlying write – there is no way to do that with the standard go io interface. So the read will happen or hang. So, use this sparingly, make sure to cancel the read as necessary (e.g. closing a connection whose context is up, etc.).
Furthermore, in order to protect your memory from being read before you've cancelled the context, this io.Reader will allocate a buffer of the same size, and **copy** into the client's if the read succeeds in time.
func NewContextReader ¶
func NewContextReader(ctx context.Context, r io.Reader) *ContextReader
NewContextReader will return a new ContextReader.