starpc 0.33.3 → 0.33.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "starpc",
3
- "version": "0.33.3",
3
+ "version": "0.33.5",
4
4
  "description": "Streaming protobuf RPC service protocol over any two-way channel.",
5
5
  "license": "MIT",
6
6
  "author": {
@@ -110,6 +110,5 @@ func (r *ClientRPC) Close() {
110
110
 
111
111
  r.bcast.HoldLock(func(broadcast func(), getWaitCh func() <-chan struct{}) {
112
112
  r.closeLocked(broadcast)
113
- broadcast()
114
113
  })
115
114
  }
@@ -69,14 +69,13 @@ func (c *commonRPC) Wait(ctx context.Context) error {
69
69
  //
70
70
  // returns io.EOF if the stream ended without a packet.
71
71
  func (c *commonRPC) ReadOne() ([]byte, error) {
72
- var msg *[]byte
72
+ var hasMsg bool
73
+ var msg []byte
73
74
  var err error
74
75
  var ctxDone bool
75
76
  for {
76
77
  var waitCh <-chan struct{}
77
78
  c.bcast.HoldLock(func(broadcast func(), getWaitCh func() <-chan struct{}) {
78
- waitCh = getWaitCh()
79
-
80
79
  if ctxDone && !c.dataClosed {
81
80
  // context must have been canceled locally
82
81
  c.closeLocked(broadcast)
@@ -85,26 +84,26 @@ func (c *commonRPC) ReadOne() ([]byte, error) {
85
84
  }
86
85
 
87
86
  if len(c.dataQueue) != 0 {
88
- msgb := c.dataQueue[0]
89
- msg = &msgb
87
+ msg = c.dataQueue[0]
88
+ hasMsg = true
90
89
  c.dataQueue[0] = nil
91
90
  c.dataQueue = c.dataQueue[1:]
92
- }
93
-
94
- if c.dataClosed || c.remoteErr != nil {
91
+ } else if c.dataClosed || c.remoteErr != nil {
95
92
  err = c.remoteErr
96
93
  if err == nil {
97
94
  err = io.EOF
98
95
  }
99
96
  }
97
+
98
+ waitCh = getWaitCh()
100
99
  })
101
100
 
102
- if err != nil {
103
- return nil, err
101
+ if hasMsg {
102
+ return msg, nil
104
103
  }
105
104
 
106
- if msg != nil {
107
- return *msg, nil
105
+ if err != nil {
106
+ return nil, err
108
107
  }
109
108
 
110
109
  select {