@nxtedition/shared 2.0.8 → 2.0.9

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.
Files changed (2) hide show
  1. package/index.js +8 -16
  2. package/package.json +1 -1
package/index.js CHANGED
@@ -33,13 +33,11 @@ async function* _reader({ sharedState, sharedBuffer }, cb) {
33
33
  continue
34
34
  }
35
35
 
36
- assert.equal(tag, -2)
36
+ assert(tag === -2, `tag: ${tag} === -2`)
37
37
 
38
38
  const len = buffer.readInt32LE(readPos)
39
39
  readPos += 4
40
40
 
41
- assert(len >= 0)
42
-
43
41
  const raw = buffer.subarray(readPos, readPos + len)
44
42
  readPos += len
45
43
 
@@ -96,19 +94,14 @@ export function writer({ sharedState, sharedBuffer }) {
96
94
  buffer.writeInt32LE(-2, writePos)
97
95
  writePos += 4
98
96
 
99
- const lenPos = writePos
100
- writePos += 4
101
-
102
- const len = fn(buffer.subarray(writePos, writePos + maxLen), opaque)
103
- assert(len <= size)
97
+ const len = fn(buffer.subarray(writePos + 4, writePos + 4 + maxLen), opaque)
98
+ assert(len <= maxLen - 4, `len: ${len} <= maxLen: ${maxLen - 4}`)
99
+ assert(len <= size, `len: ${len} <= size: ${size}`)
104
100
 
105
- writePos += len
101
+ buffer.writeInt32LE(len, writePos)
102
+ writePos += 4 + len
106
103
  buffer.writeInt32LE(-3, writePos)
107
104
 
108
- assert(len <= maxLen)
109
-
110
- buffer.writeInt32LE(len, lenPos)
111
-
112
105
  Atomics.store(state, WRITE_INDEX, writePos)
113
106
  Atomics.notify(state, WRITE_INDEX)
114
107
 
@@ -143,8 +136,8 @@ export function writer({ sharedState, sharedBuffer }) {
143
136
  fn = args[1]
144
137
  opaque = args[2]
145
138
 
146
- assert(maxLen >= 0)
147
- assert(typeof fn === 'function')
139
+ assert(maxLen >= 0, `maxLen: ${maxLen} >= 0`)
140
+ assert(typeof fn === 'function', `fn: ${typeof fn} === 'function`)
148
141
  } else {
149
142
  if (Array.isArray(args[0])) {
150
143
  args = args[0]
@@ -160,7 +153,6 @@ export function writer({ sharedState, sharedBuffer }) {
160
153
  pos += buf.copy(dst, pos)
161
154
  }
162
155
  }
163
- assert(pos < maxLen)
164
156
  return pos
165
157
  }
166
158
  opaque = args
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nxtedition/shared",
3
- "version": "2.0.8",
3
+ "version": "2.0.9",
4
4
  "description": "Ring Buffer for NodeJS cross Worker communication",
5
5
  "main": "index.js",
6
6
  "repository": {