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 {
56
56
return c .transport .Close ()
57
57
}
58
58
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
+
59
64
// Call makes a jsonrpc call
60
65
func (c * Client ) Call (method string , out interface {}, params ... interface {}) error {
61
66
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 {
27
27
return nil
28
28
}
29
29
30
+ // ErrCh implements the transport interface
31
+ func (h * HTTP ) ErrCh () chan error {
32
+ return nil
33
+ }
34
+
30
35
// Call implements the transport interface
31
36
func (h * HTTP ) Call (method string , out interface {}, params ... interface {}) error {
32
37
// Encode json-rpc request
Original file line number Diff line number Diff line change @@ -15,6 +15,8 @@ type Transport interface {
15
15
16
16
// Close closes the transport connection if necessary
17
17
Close () error
18
+
19
+ ErrCh () chan error
18
20
}
19
21
20
22
// PubSubTransport is a transport that allows subscriptions
Original file line number Diff line number Diff line change @@ -49,13 +49,15 @@ type stream struct {
49
49
subsLock sync.Mutex
50
50
subs map [string ]func (b []byte )
51
51
52
+ errCh chan error
52
53
closeCh chan struct {}
53
54
timer * time.Timer
54
55
}
55
56
56
57
func newStream (codec Codec ) (* stream , error ) {
57
58
w := & stream {
58
59
codec : codec ,
60
+ errCh : make (chan error , 1 ),
59
61
closeCh : make (chan struct {}),
60
62
handler : map [uint64 ]callback {},
61
63
subs : map [string ]func (b []byte ){},
@@ -71,6 +73,11 @@ func (s *stream) Close() error {
71
73
return s .codec .Close ()
72
74
}
73
75
76
+ // ErrCh implements the transport interface
77
+ func (s * stream ) ErrCh () chan error {
78
+ return s .errCh
79
+ }
80
+
74
81
func (s * stream ) incSeq () uint64 {
75
82
return atomic .AddUint64 (& s .seq , 1 )
76
83
}
@@ -94,6 +101,10 @@ func (s *stream) listen() {
94
101
if ! s .isClosed () {
95
102
// log error
96
103
}
104
+ select {
105
+ case s .errCh <- err :
106
+ default :
107
+ }
97
108
return
98
109
}
99
110
You can’t perform that action at this time.
0 commit comments