Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Broadcaster ¶
type Broadcaster[T any] interface { // Subscribe gets Subscriber from Broadcasters pool and appends Subscriber's active channel to // Broadcaster's active channel slice. Subscribe() Subscriber[T] // DetachAndWrite is a shorthand for "go WriteCtx()". Possible resource leak if // context.Background() or any other non-cancellable context is used. Short DetachAndWrite(ctx context.Context, data T) // WriteNonBlock uses select-default statement inside so the written data can be missed by some routines. // To prevent it use WriteCtx. WriteNonBlock(T) // WriteBlock uses select-case<-context.Background().Done() statement inside. WriteBlock(T) // WriteCtx uses select-case<-context.Context().Done() statement inside. WriteCtx(context.Context, T) }
Broadcaster allows one goroutine to write same T value to multiple goroutines sequentially.
func New ¶
func New[T any](buffer ...int) Broadcaster[T]
New creates go channel like Broadcaster. Buffer length may be passed as an argument. Args[1:] will be ignored.
type Subscriber ¶
type Subscriber[T any] interface { // Read from channel. Read returns closed channel if dispatched. Read() <-chan T // Dispatch removes Subscriber's active channel from Broadcaster's active channels slice, drains it and // puts Subscriber itself to Broadcaster's Subscribers pool. Dispatch() }
Subscriber allows goroutine to read written to Broadcaster T value.
Click to show internal directories.
Click to hide internal directories.