Notify sends a notification to the client with the given data as payload. If an error occurs the RPC connection is closed and the error is returned.
(id ID, data interface{})
| 88 | // Notify sends a notification to the client with the given data as payload. |
| 89 | // If an error occurs the RPC connection is closed and the error is returned. |
| 90 | func (n *Notifier) Notify(id ID, data interface{}) error { |
| 91 | n.subMu.RLock() |
| 92 | defer n.subMu.RUnlock() |
| 93 | |
| 94 | sub, active := n.active[id] |
| 95 | if active { |
| 96 | notification := n.codec.CreateNotification(string(id), sub.namespace, data) |
| 97 | if err := n.codec.Write(notification); err != nil { |
| 98 | n.codec.Close() |
| 99 | return err |
| 100 | } |
| 101 | } |
| 102 | return nil |
| 103 | } |
| 104 | |
| 105 | // Closed returns a channel that is closed when the RPC connection is closed. |
| 106 | func (n *Notifier) Closed() <-chan interface{} { |