func (n *Notifier) Closed() <-chan interface{} {
	return n.codec.Closed()
}
Closed returns a channel that is closed when the RPC connection is closed.
package server
import (
	"context"
	"errors"
	"reflect"
	"sync"
)
var (
	ErrNotificationsUnsupported = errors.New("notifications not supported")
	ErrSubscriptionNotFound = errors.New("subscription not found")
)
type ServerCodec interface {
	ReadRequestHeaders() ([]rpcRequest, bool, Error)
	ParseRequestArguments(argTypes []reflect.Type, params interface{}) ([]reflect.Value, Error)
	CreateResponse(id interface{}, reply interface{}) interface{}
	CreateErrorResponse(id interface{}, err Error) interface{}
	CreateErrorResponseWithInfo(id interface{}, err Error, info interface{}) interface{}
	CreateNotification(id, namespace string, event interface{}) interface{}
	Write(msg interface{}) error
	Close()
	Closed() <-chan interface{}
}
type Error interface {
	Error() string   
	ErrorCode() int  
}
type ID string
type Subscription struct {
	ID        ID
	namespace string
	err       chan error  
}
func (s *Subscription) Err() <-chan error {
	return s.err
}
type notifierKey struct{}
type Notifier struct {
	codec    ServerCodec
	subMu    sync.RWMutex  
	active   map[ID]*Subscription
	inactive map[ID]*Subscription
}
func newNotifier(codec ServerCodec) *Notifier {
	return &Notifier{
		codec:    codec,
		active:   make(map[ID]*Subscription),
		inactive: make(map[ID]*Subscription),
	}
}
func NotifierFromContext(ctx context.Context) (*Notifier, bool) {
	n, ok := ctx.Value(notifierKey{}).(*Notifier)
	return n, ok
}
func (n *Notifier) CreateSubscription() *Subscription {
	s := &Subscription{ID: NewID(), err: make(chan error)}
	n.subMu.Lock()
	n.inactive[s.ID] = s
	n.subMu.Unlock()
	return s
}
func (n *Notifier) Notify(id ID, data interface{}) error {
	n.subMu.RLock()
	defer n.subMu.RUnlock()
	sub, active := n.active[id]
	if active {
		notification := n.codec.CreateNotification(string(id), sub.namespace, data)
		if err := n.codec.Write(notification); err != nil {
			n.codec.Close()
			return err
		}
	}
	return nil
}