Skip to content

Commit

Permalink
Merge pull request #147 from libp2p/feat/subscribes-to-events
Browse files Browse the repository at this point in the history
feat: add a function to tell if a context subscribes to query events
  • Loading branch information
Stebalien committed Apr 29, 2020
2 parents d511b7a + 6be155f commit 7b406c1
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions core/routing/query.go
Expand Up @@ -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
}

0 comments on commit 7b406c1

Please sign in to comment.