Merge pull request #147 from libp2p/feat/subscribes-to-events

feat: add a function to tell if a context subscribes to query events
This commit is contained in:
Steven Allen 2020-04-29 13:21:46 -07:00 committed by GitHub
commit a4b837bc12
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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
}