File tree Expand file tree Collapse file tree 4 files changed +23
-0
lines changed Expand file tree Collapse file tree 4 files changed +23
-0
lines changed Original file line number Diff line number Diff line change @@ -56,6 +56,11 @@ func (c *Client) Close() error {
5656 return c .transport .Close ()
5757}
5858
59+ // ErrCh returns a chan to send errors that occurred in the client
60+ func (c * Client ) ErrCh () chan error {
61+ return c .transport .ErrCh ()
62+ }
63+
5964// Call makes a jsonrpc call
6065func (c * Client ) Call (method string , out interface {}, params ... interface {}) error {
6166 return c .transport .Call (method , out , params ... )
Original file line number Diff line number Diff line change @@ -27,6 +27,11 @@ func (h *HTTP) Close() error {
2727 return nil
2828}
2929
30+ // ErrCh implements the transport interface
31+ func (h * HTTP ) ErrCh () chan error {
32+ return nil
33+ }
34+
3035// Call implements the transport interface
3136func (h * HTTP ) Call (method string , out interface {}, params ... interface {}) error {
3237 // Encode json-rpc request
Original file line number Diff line number Diff line change @@ -15,6 +15,8 @@ type Transport interface {
1515
1616 // Close closes the transport connection if necessary
1717 Close () error
18+
19+ ErrCh () chan error
1820}
1921
2022// PubSubTransport is a transport that allows subscriptions
Original file line number Diff line number Diff line change @@ -49,13 +49,15 @@ type stream struct {
4949 subsLock sync.Mutex
5050 subs map [string ]func (b []byte )
5151
52+ errCh chan error
5253 closeCh chan struct {}
5354 timer * time.Timer
5455}
5556
5657func newStream (codec Codec ) (* stream , error ) {
5758 w := & stream {
5859 codec : codec ,
60+ errCh : make (chan error , 1 ),
5961 closeCh : make (chan struct {}),
6062 handler : map [uint64 ]callback {},
6163 subs : map [string ]func (b []byte ){},
@@ -71,6 +73,11 @@ func (s *stream) Close() error {
7173 return s .codec .Close ()
7274}
7375
76+ // ErrCh implements the transport interface
77+ func (s * stream ) ErrCh () chan error {
78+ return s .errCh
79+ }
80+
7481func (s * stream ) incSeq () uint64 {
7582 return atomic .AddUint64 (& s .seq , 1 )
7683}
@@ -94,6 +101,10 @@ func (s *stream) listen() {
94101 if ! s .isClosed () {
95102 // log error
96103 }
104+ select {
105+ case s .errCh <- err :
106+ default :
107+ }
97108 return
98109 }
99110
You can’t perform that action at this time.
0 commit comments