Documentation
¶
Overview ¶
Package lossy contains wait/notify and pub/sub implementations that can lose data.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func NewNotifier ¶
NewNotifier creates a new pair of Notifier/Waiter.
It provides a lossy wait/notify implementation.
They shares a channel, which is closed by [Notifier.Notify]. After the channel is closed, a new channel is shared instead, so further notification is lost before you wait again.
Types ¶
type Notifier ¶
type Notifier interface {
// Notifies current waiting waiters.
Notify()
}
Notifier is a channel-based lossy notifier, coupled with Waiter.
It notifies current waiters, and prepares for next notification.
See [Waiter.Wait] for detailed info.
type Pub ¶
type Pub[T any] interface { // Publishs v to current subscribers. V(v T) // Publish an error to current subscribers. E(e error) }
Pub is a [future.Future] based lossy publisher.
Take a look at [Sub.Sub] for detailed info.
type Sub ¶
type Sub[T any] interface { // Subscribes single value. Returned future is resolved by next Pub.V or // rejected by Pub.E. You'll lose further values before you subscribe again. Sub() tbd.TBD[T] }
Sub is a [future.Future] based lossy subscriber.
It receives only one value once you called Sub().
type Waiter ¶
type Waiter interface {
// Waits for next notification. Returned channel is closed by next
// Notifier.Notify call. You'll lose further notifications before
// you wait again.
Wait() <-chan struct{}
// A cancellable wait.
WaitCtx(context.Context) error
}
Waiter is a channel-bases lossy waiter, coupled with Notifier.
It receives only one notification once you call Wait().