io

package
v1.0.0-beta.7 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 30, 2019 License: Apache-2.0 Imports: 2 Imported by: 0

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.

func (*ContextReader) Read

func (r *ContextReader) Read(p []byte) (int, error)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL