mirror of
https://github.com/logos-messaging/go-libp2p-pubsub.git
synced 2026-01-05 22:33:10 +00:00
add PubSub's context to Subscription
This commit is contained in:
parent
9f04364996
commit
9d03237eec
@ -696,6 +696,7 @@ func (p *PubSub) SubscribeByTopicDescriptor(td *pb.TopicDescriptor, opts ...SubO
|
|||||||
|
|
||||||
sub := &Subscription{
|
sub := &Subscription{
|
||||||
topic: td.GetName(),
|
topic: td.GetName(),
|
||||||
|
ctx: p.ctx,
|
||||||
|
|
||||||
ch: make(chan *Message, 32),
|
ch: make(chan *Message, 32),
|
||||||
peerEvtCh: make(chan PeerEvent, 1),
|
peerEvtCh: make(chan PeerEvent, 1),
|
||||||
|
|||||||
@ -18,6 +18,7 @@ type Subscription struct {
|
|||||||
ch chan *Message
|
ch chan *Message
|
||||||
cancelCh chan<- *Subscription
|
cancelCh chan<- *Subscription
|
||||||
err error
|
err error
|
||||||
|
ctx context.Context
|
||||||
|
|
||||||
peerEvtCh chan PeerEvent
|
peerEvtCh chan PeerEvent
|
||||||
evtLogMx sync.Mutex
|
evtLogMx sync.Mutex
|
||||||
@ -49,7 +50,10 @@ func (sub *Subscription) Next(ctx context.Context) (*Message, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (sub *Subscription) Cancel() {
|
func (sub *Subscription) Cancel() {
|
||||||
sub.cancelCh <- sub
|
select {
|
||||||
|
case sub.cancelCh <- sub:
|
||||||
|
case <-sub.ctx.Done():
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (sub *Subscription) close() {
|
func (sub *Subscription) close() {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user