channels

package
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: Jul 26, 2026 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BrokenSinkError

func BrokenSinkError() error

Types

type ChanElem

type ChanElem[T any] struct {
	// contains filtered or unexported fields
}

func WrapChanData

func WrapChanData[T any](data T) ChanElem[T]

func WrapChanErr

func WrapChanErr[T any](err error) ChanElem[T]

func (*ChanElem[T]) Data

func (e *ChanElem[T]) Data() T

func (*ChanElem[T]) Err

func (e *ChanElem[T]) Err() error

func (*ChanElem[T]) SendTo

func (e *ChanElem[T]) SendTo(ch chan<- ChanElem[T], context context.Context) bool

type StreamingChan

type StreamingChan[T any] <-chan ChanElem[T]

func CreateChannel

func CreateChannel[T any](generator func(sink func(data T, context context.Context) bool) error) StreamingChan[T]

func CreateChannelBuffered

func CreateChannelBuffered[T any](bufSize int, generator func(sink func(data []T, context context.Context) bool) error) StreamingChan[T]

func CreateChannelBufferedContext added in v0.6.0

func CreateChannelBufferedContext[T any](ctx context.Context, bufSize int, generator func(sink func(data []T, sendContext context.Context) bool) error) StreamingChan[T]

CreateChannelBufferedContext creates a context-owned stream with the exact requested finite capacity. Each page is delivered in order, one element at a time, and cancellation interrupts blocked value and terminal-error sends.

func CreateChannelContext added in v0.6.0

func CreateChannelContext[T any](ctx context.Context, generator func(sink func(data T, sendContext context.Context) bool) error) StreamingChan[T]

CreateChannelContext creates an unbuffered context-owned stream. The generator must return after sink reports false. A non-nil generator error is sent at most once while the operation context remains active.

func FlapMap

func FlapMap[P any, Q any](ch StreamingChan[P], mapper func(data P) StreamingChan[Q]) StreamingChan[Q]

func FlatMapContext added in v0.6.0

func FlatMapContext[P any, Q any](ctx context.Context, ch StreamingChan[P], mapper func(data P) StreamingChan[Q]) StreamingChan[Q]

FlatMapContext expands source values in order while all owned receives and sends observe the same operation context. FlapMap remains available for compatibility with its historical spelling.

func Map

func Map[P any, Q any](ch StreamingChan[P], mapper func(data P) Q) StreamingChan[Q]

func MapContext added in v0.6.0

func MapContext[P any, Q any](ctx context.Context, ch StreamingChan[P], mapper func(data P) Q) StreamingChan[Q]

MapContext maps source values in order and shares ctx across receiving and sending so an abandoned chain can be canceled as one operation.

func SingleElemChannel

func SingleElemChannel[T any](data T) StreamingChan[T]

func SingleElemChannelContext added in v0.6.0

func SingleElemChannelContext[T any](ctx context.Context, data T) StreamingChan[T]

SingleElemChannelContext returns an unbuffered, producer-owned stream whose only send is abandoned when the operation context is canceled.

func SingleElemChannelErr

func SingleElemChannelErr[T any](data T, err error) StreamingChan[T]

func SingleElemChannelErrContext added in v0.6.0

func SingleElemChannelErrContext[T any](ctx context.Context, data T, err error) StreamingChan[T]

SingleElemChannelErrContext returns either one value or one terminal error. Cancellation suppresses a send that has not completed yet.

func SliceToChannel

func SliceToChannel[T any](data []T) StreamingChan[T]

func SliceToChannelContext added in v0.6.0

func SliceToChannelContext[T any](ctx context.Context, data []T) StreamingChan[T]

SliceToChannelContext streams data in source order until completion or cancellation. The returned unbuffered channel is always closed by its producer.

func (StreamingChan[T]) CollectToSlice

func (ch StreamingChan[T]) CollectToSlice() ([]T, error)

func (StreamingChan[T]) CollectToSliceContext added in v0.6.0

func (ch StreamingChan[T]) CollectToSliceContext(ctx context.Context) ([]T, error)

CollectToSliceContext collects values received before completion or cancellation. Partial values are returned together with the terminal error.

func (StreamingChan[T]) FlatMap

func (ch StreamingChan[T]) FlatMap(mapper func(data T) StreamingChan[any]) StreamingChan[any]

func (StreamingChan[T]) ForEachChanElem

func (ch StreamingChan[T]) ForEachChanElem(onEach func(data T) error) error

func (StreamingChan[T]) ForEachChanElemContext added in v0.6.0

func (ch StreamingChan[T]) ForEachChanElemContext(ctx context.Context, onEach func(data T) error) error

ForEachChanElemContext consumes values until closure, a terminal stream error, callback failure, or operation cancellation.

func (StreamingChan[T]) Map

func (ch StreamingChan[T]) Map(mapper func(data T) any) StreamingChan[any]

Jump to

Keyboard shortcuts

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