type Subscriber … type PubSub … // NewPubSub returns a new PubSub instance. Users should cancel the // provided context to shutdown the PubSub. func NewPubSub(ctx context.Context) *PubSub { … } // Subscribe registers the provided Subscriber to the PubSub. // // If the PubSub contains a previously published message, the Subscriber's // OnMessage() callback will be invoked asynchronously with the existing // message to begin with, and subsequently for every newly published message. // // The caller is responsible for invoking the returned cancel function to // unsubscribe itself from the PubSub. func (ps *PubSub) Subscribe(sub Subscriber) (cancel func()) { … } // Publish publishes the provided message to the PubSub, and invokes // callbacks registered by subscribers asynchronously. func (ps *PubSub) Publish(msg any) { … } // Done returns a channel that is closed after the context passed to NewPubSub // is canceled and all updates have been sent to subscribers. func (ps *PubSub) Done() <-chan struct{ … }