From 5d9ec0280bf35787e6422ab452504e19d6f958e9 Mon Sep 17 00:00:00 2001 From: Steven Allen Date: Wed, 29 Apr 2020 13:11:46 -0700 Subject: [PATCH] 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. --- routing/query.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/routing/query.go b/routing/query.go index 42acdb1..26743af 100644 --- a/routing/query.go +++ b/routing/query.go @@ -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 +} -- GitLab