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.N]. After the channel is closed, a new channel is shared instead, so further notification is lost before you wait again.
func NewPubSub ¶
NewPubSub creates a new pair of Pub/Sub.
It provides a lossy publish/subscribe implementation.
They shares an unresolved future.Future, which is resolved (or rejected) by publishing. After the future is resolved, you lost further publishing before subcribe again.
Types ¶
type Notifier ¶
type Notifier interface {
// Notifies current waiting waiters.
N()
}
Notifier is a channel-based lossy notifier, coupled with Waiter.
It notifies current waiters, and prepares for next notification.
See [Waiter.W] 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() *future.Future[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.N call. You'll lose further notifications before you
// wait again.
W() <-chan struct{}
}
Waiter is a channel-bases lossy waiter, coupled with Notifier.
It receives only one notification once you call W().