Help us shape the future of Go! Take the 2026 Go Developer Survey

multichan

package module
v1.0.2-0...-991b813 Latest Latest
Warning

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

Go to latest
Published: Feb 20, 2019 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package multichan provides a one-to-many data channel.

The source of some data creates a writer (type multichan.W) and supplies items to it one at a time with W.Write.

Consumers of those items create readers with W.Reader (producing a multichan.R) and read items with R.Read and R.NBRead.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type R

type R struct {
	// contains filtered or unexported fields
}

R is the reading end of a one-to-many data channel.

func (*R) Dispose

func (r *R) Dispose()

Dispose removes r from its multichan, freeing up resources. It is an error to make further method calls on r after Dispose.

func (*R) NBRead

func (r *R) NBRead() (interface{}, bool)

NBRead does a non-blocking read on the multichan. If the multichan is closed and the last item has already been consumed, or if no next item is ready to read, this returns the multichan's zero value (see New) and false. Otherwise it returns the next value and true.

func (*R) Read

func (r *R) Read(ctx context.Context) (interface{}, bool)

Read reads the next item in the multichan. It blocks until an item is ready to read or its context is canceled. If the multichan is closed and the last item has already been consumed, or the context is canceled, this returns the multichan's zero value (see New) and false. Otherwise it returns the next value and true. The context argument may be nil.

type W

type W struct {
	// contains filtered or unexported fields
}

W is the writing end of a one-to-many data channel.

func New

func New(zero interface{}) *W

New produces a new multichan writer. Its argument is the zero value that readers will see when reading from a closed multichan, (or when non-blockingly reading from an unready multichan).

func (*W) Close

func (w *W) Close()

Close closes the writing end of a multichan, signaling to readers that the stream has ended. Reading past the end of the stream produces the zero value that was passed to New.

func (*W) Reader

func (w *W) Reader() *R

Reader adds a new reader to the multichan and returns it. Readers consume resources in the multichan and should be disposed of (with Dispose) when no longer needed.

func (*W) Write

func (w *W) Write(val interface{})

Write adds an item to the multichan. Its type must match (i.e., must be assignable to <https://golang.org/ref/spec#Assignability>) that of the zero value passed to New.

Each item written to w remains in an internal queue until the last reader has consumed it. Readers added later to a multichan may miss items added earlier.

Jump to

Keyboard shortcuts

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