From c94ae093c150e7889f2b8020c09c14ebacf8e3a0 Mon Sep 17 00:00:00 2001 From: stanstacks Date: Fri, 23 Dec 2022 10:03:40 +0800 Subject: [PATCH] problem: close channel to unsub is confusing --- README.md | 2 +- relaypool.go | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 08c5c4f..8104aaf 100644 --- a/README.md +++ b/README.md @@ -38,7 +38,7 @@ go func() { }() time.Sleep(5 * time.Second) -close(unsub) +unsub() ``` ### Publishing an event diff --git a/relaypool.go b/relaypool.go index 57033e5..5c15b2f 100644 --- a/relaypool.go +++ b/relaypool.go @@ -124,7 +124,7 @@ func (r *RelayPool) Remove(url string) { } } -func (r *RelayPool) Sub(filters Filters) (string, chan EventMessage, chan struct{}) { +func (r *RelayPool) Sub(filters Filters) (string, chan EventMessage, func()) { random := make([]byte, 7) rand.Read(random) id := hex.EncodeToString(random) @@ -154,7 +154,7 @@ func (r *RelayPool) Sub(filters Filters) (string, chan EventMessage, chan struct return true }) - return id, eventStream, unsub + return id, eventStream, func() { close(unsub) } } func Unique(all chan EventMessage) chan Event {