aboutsummaryrefslogtreecommitdiffstats
path: root/rpc/notification.go
diff options
context:
space:
mode:
authorFelix Lange <fjl@twurst.com>2016-04-16 00:05:24 +0800
committerFelix Lange <fjl@twurst.com>2016-04-16 00:10:52 +0800
commita40e61b4ac44a4f64f057a4220a26cfe4b9dcf03 (patch)
tree401218a5f3ed5b4fac88baf87551bd3f57f3c34b /rpc/notification.go
parent6197fbf8d70c1aa96c3e87de91ff3f46f454c1ea (diff)
downloadgo-tangerine-a40e61b4ac44a4f64f057a4220a26cfe4b9dcf03.tar
go-tangerine-a40e61b4ac44a4f64f057a4220a26cfe4b9dcf03.tar.gz
go-tangerine-a40e61b4ac44a4f64f057a4220a26cfe4b9dcf03.tar.bz2
go-tangerine-a40e61b4ac44a4f64f057a4220a26cfe4b9dcf03.tar.lz
go-tangerine-a40e61b4ac44a4f64f057a4220a26cfe4b9dcf03.tar.xz
go-tangerine-a40e61b4ac44a4f64f057a4220a26cfe4b9dcf03.tar.zst
go-tangerine-a40e61b4ac44a4f64f057a4220a26cfe4b9dcf03.zip
rpc: remove NotifierContextKey
Context keys must have a unique type in order to prevent any unintented clashes. The code used int(1) as key. Fix it by implementing the pattern recommended by package context.
Diffstat (limited to 'rpc/notification.go')
-rw-r--r--rpc/notification.go9
1 files changed, 9 insertions, 0 deletions
diff --git a/rpc/notification.go b/rpc/notification.go
index 146d785c9..e84e26a58 100644
--- a/rpc/notification.go
+++ b/rpc/notification.go
@@ -23,6 +23,7 @@ import (
"github.com/ethereum/go-ethereum/logger"
"github.com/ethereum/go-ethereum/logger/glog"
+ "golang.org/x/net/context"
)
var (
@@ -62,6 +63,14 @@ type Notifier interface {
Unsubscribe(id string) error
}
+type notifierKey struct{}
+
+// NotifierFromContext returns the Notifier value stored in ctx, if any.
+func NotifierFromContext(ctx context.Context) (Notifier, bool) {
+ n, ok := ctx.Value(notifierKey{}).(Notifier)
+ return n, ok
+}
+
// Subscription defines the interface for objects that can notify subscribers
type Subscription interface {
// Inform client of an event