mirror of
https://github.com/libp2p/go-libp2p-core.git
synced 2025-03-23 12:30:08 +08:00
feat: add a function to tell if a context subscribes to query events
This can save us some work if the caller doesn't actually care about these events.
This commit is contained in:
parent
a14197ce56
commit
5d9ec0280b
@ -102,3 +102,10 @@ func PublishQueryEvent(ctx context.Context, ev *QueryEvent) {
|
||||
ech := ich.(*eventChannel)
|
||||
ech.send(ctx, ev)
|
||||
}
|
||||
|
||||
// SubscribesToQueryEvents returns true if the context subscribes to query
|
||||
// events. If this function returns falls, calling `PublishQueryEvent` on the
|
||||
// context will be a no-op.
|
||||
func SubscribesToQueryEvents(ctx context.Context) bool {
|
||||
return ctx.Value(routingQueryKey{}) != nil
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user