ctxio

package
v1.3.5-beta1 Latest Latest
Warning

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

Go to latest
Published: Aug 2, 2024 License: AGPL-3.0 Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewConn

func NewConn(ctx context.Context, conn net.Conn) net.Conn

func NewReader

func NewReader(ctx context.Context, r io.Reader) *ctxReader

NewReader wraps a reader to make it respect given Context. If there is a blocking read, the returned Reader will return whenever the context is cancelled (the return values are n=0 and err=ctx.Err().)

Note well: 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 and write _will_ happen or hang. So, use this sparingly, make sure to cancel the read or write as necesary (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 NewReaderWriter

func NewReaderWriter(ctx context.Context, r io.ReadWriter) *ctxReaderWriter

func NewWriter

func NewWriter(ctx context.Context, w io.Writer) *ctxWriter

NewWriter wraps a writer to make it respect given Context. If there is a blocking write, the returned Writer will return whenever the context is cancelled (the return values are n=0 and err=ctx.Err().)

Note well: 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 and write _will_ happen or hang. So, use this sparingly, make sure to cancel the read or write as necesary (e.g. closing a connection whose context is up, etc.)

Furthermore, in order to protect your memory from being read _after_ you've cancelled the context, this io.Writer will first make a **copy** of the buffer.

Types

type Reader

type Reader interface {
	io.Reader
}

type Writer

type Writer interface {
	io.Writer
}

Jump to

Keyboard shortcuts

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