Documentation
¶
Overview ¶
Package gochan provides specialized channel architectures inspired by Rust.
Sentinel errors defined here are shared across all subpackages.
Index ¶
Constants ¶
This section is empty.
Variables ¶
Functions ¶
This section is empty.
Types ¶
type ErrLagged ¶
type ErrLagged struct{ Missed uint64 }
ErrLagged is returned by broadcast receivers that have fallen behind the ring buffer. Missed reports how many values were overwritten before the receiver caught up; the receiver's read position is advanced to the oldest still-buffered value and remains usable.
type Receiver ¶
type Receiver[T any] interface { // Recv blocks until a value is available or the channel is closed. Recv() (T, error) // TryRecv returns immediately without blocking. Returns the next // value, or one of: ErrEmpty (nothing buffered), ErrClosed // (sender/hub closed and nothing left to drain), ErrNotReady // (queue-style packages — no counterparty has registered yet), // ErrLagged (broadcast — receiver fell behind, see package docs). TryRecv() (T, error) // RecvContext blocks like Recv but returns ctx.Err() if ctx is cancelled. RecvContext(ctx context.Context) (T, error) // Chan returns a native channel for use with select. Chan() <-chan T // Close is idempotent. Close() }
Receiver is the common receive-side interface implemented by every channel type in this module.
type Sender ¶
type Sender[T any] interface { // Send delivers v. On queue-style packages (spsc, spmc, mpsc, mpmc) // Send blocks until the value is accepted by the channel or the // channel is closed. On oneshot, broadcast, and watch Send never // blocks — it publishes immediately and returns. Returns ErrClosed // if the sender or hub has been closed. Send(v T) error // TrySend returns immediately without blocking. Returns nil on // success, or one of: ErrFull (no room to enqueue), ErrClosed // (sender/hub closed), ErrNotReady (queue-style packages — no // counterparty has registered yet). TrySend(v T) error // SendContext blocks like Send but returns ctx.Err() if ctx is cancelled. SendContext(ctx context.Context, v T) error // Close is idempotent. Close() }
Sender is the common send-side interface implemented by every channel type in this module.
Directories
¶
| Path | Synopsis |
|---|---|
|
Package broadcast provides a fan-out channel backed by a fixed-size ring buffer.
|
Package broadcast provides a fan-out channel backed by a fixed-size ring buffer. |
|
examples/chan
command
broadcast/examples/chan demonstrates the Chan()-based API for a fan-out channel, with subscribers composing Chan() with a cancel signal via select for graceful early shutdown.
|
broadcast/examples/chan demonstrates the Chan()-based API for a fan-out channel, with subscribers composing Chan() with a cancel signal via select for graceful early shutdown. |
|
examples/recv
command
broadcast/examples/recv demonstrates the Recv()-based API for a fan-out channel: every value goes to every live subscriber.
|
broadcast/examples/recv demonstrates the Recv()-based API for a fan-out channel: every value goes to every live subscriber. |
|
internal
|
|
|
chancore
Package chancore holds shared building blocks for the gochan subpackages.
|
Package chancore holds shared building blocks for the gochan subpackages. |
|
Package mpmc provides a multi-producer, multi-consumer FIFO queue.
|
Package mpmc provides a multi-producer, multi-consumer FIFO queue. |
|
examples/chan
command
mpmc/examples/chan demonstrates the Chan()-based API for a multi-producer / multi-consumer queue.
|
mpmc/examples/chan demonstrates the Chan()-based API for a multi-producer / multi-consumer queue. |
|
examples/recv
command
mpmc/examples/recv demonstrates the Recv()-based API for a multi-producer / multi-consumer queue.
|
mpmc/examples/recv demonstrates the Recv()-based API for a multi-producer / multi-consumer queue. |
|
Package mpsc provides a multi-producer, single-consumer FIFO queue.
|
Package mpsc provides a multi-producer, single-consumer FIFO queue. |
|
examples/chan
command
mpsc/examples/chan demonstrates the Chan()-based API for a multi-producer / single-consumer fan-in queue, with the consumer composing the receive channel with a cancel signal via select.
|
mpsc/examples/chan demonstrates the Chan()-based API for a multi-producer / single-consumer fan-in queue, with the consumer composing the receive channel with a cancel signal via select. |
|
examples/recv
command
mpsc/examples/recv demonstrates the Recv()-based API for a multi-producer / single-consumer fan-in queue.
|
mpsc/examples/recv demonstrates the Recv()-based API for a multi-producer / single-consumer fan-in queue. |
|
Package oneshot provides a single-value, single-delivery channel.
|
Package oneshot provides a single-value, single-delivery channel. |
|
examples/chan
command
oneshot/examples/chan demonstrates the Chan()-based API for a single-value handoff, composed with other events in a select.
|
oneshot/examples/chan demonstrates the Chan()-based API for a single-value handoff, composed with other events in a select. |
|
examples/recv
command
oneshot/examples/recv demonstrates the Recv()-based API for a single-value request/response handoff.
|
oneshot/examples/recv demonstrates the Recv()-based API for a single-value request/response handoff. |
|
Package spmc provides a single-producer, multi-consumer FIFO queue.
|
Package spmc provides a single-producer, multi-consumer FIFO queue. |
|
examples/chan
command
spmc/examples/chan demonstrates the Chan()-based API for a single-producer / multi-consumer work-distribution queue, with workers using select to compose the channel with a cancel signal.
|
spmc/examples/chan demonstrates the Chan()-based API for a single-producer / multi-consumer work-distribution queue, with workers using select to compose the channel with a cancel signal. |
|
examples/recv
command
spmc/examples/recv demonstrates the Recv()-based API for a single-producer / multi-consumer work-distribution queue.
|
spmc/examples/recv demonstrates the Recv()-based API for a single-producer / multi-consumer work-distribution queue. |
|
Package spsc provides a single-producer, single-consumer FIFO queue.
|
Package spsc provides a single-producer, single-consumer FIFO queue. |
|
examples/chan
command
spsc/examples/chan demonstrates the Chan()-based API for a single-producer / single-consumer queue, composed with a cancellation channel via select.
|
spsc/examples/chan demonstrates the Chan()-based API for a single-producer / single-consumer queue, composed with a cancellation channel via select. |
|
examples/recv
command
spsc/examples/recv demonstrates the Recv()-based API for a single-producer / single-consumer queue.
|
spsc/examples/recv demonstrates the Recv()-based API for a single-producer / single-consumer queue. |
|
Package watch provides a single-producer, multi-consumer latest-value channel.
|
Package watch provides a single-producer, multi-consumer latest-value channel. |
|
examples/chan
command
watch/examples/chan demonstrates the Chan()-based API for a latest-value-only channel, with the subscriber composing Chan() with a cancel signal via select for graceful early shutdown.
|
watch/examples/chan demonstrates the Chan()-based API for a latest-value-only channel, with the subscriber composing Chan() with a cancel signal via select for graceful early shutdown. |
|
examples/recv
command
watch/examples/recv demonstrates the Recv()-based API for a latest-value-only channel — the classic "current config" pattern.
|
watch/examples/recv demonstrates the Recv()-based API for a latest-value-only channel — the classic "current config" pattern. |
Click to show internal directories.
Click to hide internal directories.