problem: close channel to unsub is confusing

This commit is contained in:
stanstacks 2022-12-23 10:03:40 +08:00
parent 6f1c60f66c
commit c94ae093c1
2 changed files with 3 additions and 3 deletions

View File

@ -38,7 +38,7 @@ go func() {
}()
time.Sleep(5 * time.Second)
close(unsub)
unsub()
```
### Publishing an event

View File

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