Source File
subscription.go
Belonging Package
github.com/libp2p/go-libp2p-pubsub
package pubsubimport ()// Subscription handles the details of a particular Topic subscription.// There may be many subscriptions for a given Topic.type Subscription struct {topic stringch chan *MessagecancelCh chan<- *Subscriptionctx context.Contexterr erroronce sync.Once}// Topic returns the topic string associated with the Subscriptionfunc ( *Subscription) () string {return .topic}// Next returns the next message in our subscriptionfunc ( *Subscription) ( context.Context) (*Message, error) {select {case , := <-.ch:if ! {return , .err}return , nilcase <-.Done():return nil, .Err()}}// Cancel closes the subscription. If this is the last active subscription then pubsub will send an unsubscribe// announcement to the network.func ( *Subscription) () {select {case .cancelCh <- :case <-.ctx.Done():}}func ( *Subscription) () {.once.Do(func() {close(.ch)})}
![]() |
The pages are generated with Golds v0.8.2. (GOOS=linux GOARCH=amd64) Golds is a Go 101 project developed by Tapir Liu. PR and bug reports are welcome and can be submitted to the issue list. Please follow @zigo_101 (reachable from the left QR code) to get the latest news of Golds. |