cancellable

package
v0.0.3 Latest Latest
Warning

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

Go to latest
Published: Aug 21, 2024 License: MIT Imports: 1 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var CHANBUFSIZE = 1000 // default buffer size for NewChan

Functions

This section is empty.

Types

type Cancellable

type Cancellable interface {
	context.Context
	Cancel(err error)            // stop listening and close connection. does not close chan.
	GetContext() context.Context // for interface compatibility (returns underlying Context, not self)
	Wait() error                 // wait for context to be done, return underlying error cause
}

Cancellable is a context.Context that provides a Cancel func.

func New

func New(parent context.Context) Cancellable

New cancellable (must Cancel to prevent context leak)

func NewFrom

func NewFrom(the context.Context, cancelfunc context.CancelCauseFunc) Cancellable

NewFrom wraps existing context and cancelfunc to provide same interface as New

type Chan

type Chan[T any] interface {
	Cancellable
	UpdatesChan() <-chan T // Returns chan for receiving. choose 1: only use if NOT using Updates()
	Updates() []T          // Collects recent sent-to-chan. choose 1: only use if NOT using UpdatesChan()
	Updates2() []T         // TODO: benchmark this against Updates()
	CloseChan()            // manual, optional: only when no more sending to chan
	Ch() chan<- T          // sender only
}

Chan holds a context and channel and cancelfunc.

func NewChan

func NewChan[T any](parent context.Context) Chan[T]

NewChan for type T (must Cancel, optionally CloseChan)

func NewChanFrom

func NewChanFrom[T any](parent context.Context, cancelfunc context.CancelCauseFunc) Chan[T]

NewChanFrom for type T (must Cancel, optionally CloseChan)

func WrapChan

func WrapChan[T any](parent context.Context, cancelfunc context.CancelCauseFunc, ch chan T) Chan[T]

WrapChan for pre-existing channel. All fields may be nil for behavior like NewChanFrom

Jump to

Keyboard shortcuts

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