File tree Expand file tree Collapse file tree 1 file changed +21
-0
lines changed
Expand file tree Collapse file tree 1 file changed +21
-0
lines changed Original file line number Diff line number Diff line change @@ -9,6 +9,7 @@ package ttx
99import (
1010 "context"
1111 "encoding/base64"
12+ "time"
1213
1314 "github.com/hyperledger-labs/fabric-smart-client/platform/view/view"
1415 "github.com/pkg/errors"
@@ -127,3 +128,23 @@ func (s *localSession) Receive() <-chan *view.Message {
127128func (s * localSession ) Close () {
128129 s .info .Closed = true
129130}
131+
132+ func ReadMessage (session view.Session , timeout time.Duration ) ([]byte , error ) {
133+ timer := time .NewTimer (timeout )
134+ defer timer .Stop ()
135+
136+ ch := session .Receive ()
137+ select {
138+ case msg := <- ch :
139+ if msg == nil {
140+ return nil , errors .New ("received nil tx" )
141+ }
142+ if msg .Status == view .ERROR {
143+ return nil , errors .New (string (msg .Payload ))
144+ }
145+ return msg .Payload , nil
146+ case <- timer .C :
147+ err := errors .New ("timeout reached" )
148+ return nil , err
149+ }
150+ }
You can’t perform that action at this time.
0 commit comments