iochan

package
v1.15.0 Latest Latest
Warning

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

Go to latest
Published: Dec 8, 2021 License: Apache-2.0 Imports: 1 Imported by: 0

Documentation

Overview

Package iochan provides a channel-based io.Reader.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ReadRequest

type ReadRequest struct {
	// Buf is the read buffer into which data should be read.
	Buf []byte
	// contains filtered or unexported fields
}

ReadRequest holds the buffer and response channel for a read request.

func (*ReadRequest) Respond

func (rr *ReadRequest) Respond(n int, err error)

Respond responds to the Read request. Respond must not be called concurrently with Reader.Close.

type Reader

type Reader struct {
	// C can be used for receiving read requests.
	//
	// Once a read request is received, it must be responded
	// to, in order to avoid blocking the reader.
	C <-chan ReadRequest
	// contains filtered or unexported fields
}

Reader is a channel-based io.Reader.

Reader is safe for use in a single producer, single consumer pattern.

func NewReader

func NewReader() *Reader

NewReader returns a new Reader.

func (*Reader) CloseRead

func (r *Reader) CloseRead(err error) error

CloseRead closes the reader such that any waiting or future Reads return err. Additional calls to CloseRead have no effect. CloseRead must not be called concurrently with ReadRequest.Respond.

func (*Reader) CloseWrite

func (r *Reader) CloseWrite()

CloseWrite closes reader.C. CloseWrite is idempotent, but must not be called concurrently with Read.

func (*Reader) Read

func (r *Reader) Read(buf []byte) (int, error)

Read sends a ReadRequest to r.C containing buf, and returns the response sent by the channel consumer via the read request's Response method.

Jump to

Keyboard shortcuts

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