@nxtedition/shared 2.0.10 → 2.0.11
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/index.js +22 -25
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -44,7 +44,10 @@ async function* _reader({ sharedState, sharedBuffer }, cb) {
|
|
|
44
44
|
readPos += len
|
|
45
45
|
|
|
46
46
|
if (cb) {
|
|
47
|
-
|
|
47
|
+
const thenable = cb(raw)
|
|
48
|
+
if (thenable) {
|
|
49
|
+
await thenable
|
|
50
|
+
}
|
|
48
51
|
} else {
|
|
49
52
|
yield raw
|
|
50
53
|
}
|
|
@@ -110,19 +113,17 @@ export function writer({ sharedState, sharedBuffer }) {
|
|
|
110
113
|
return true
|
|
111
114
|
}
|
|
112
115
|
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
// }
|
|
125
|
-
// }
|
|
116
|
+
function defaultWrite(dst, data) {
|
|
117
|
+
let pos = 0
|
|
118
|
+
for (const buf of data) {
|
|
119
|
+
if (typeof buf === 'string') {
|
|
120
|
+
pos += dst.write(buf, pos)
|
|
121
|
+
} else {
|
|
122
|
+
pos += buf.copy(dst, pos)
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
return pos
|
|
126
|
+
}
|
|
126
127
|
|
|
127
128
|
function write(...args) {
|
|
128
129
|
if (!args.length) {
|
|
@@ -145,22 +146,18 @@ export function writer({ sharedState, sharedBuffer }) {
|
|
|
145
146
|
args = args[0]
|
|
146
147
|
}
|
|
147
148
|
|
|
148
|
-
maxLen =
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
for (const buf of data) {
|
|
152
|
-
if (typeof buf === 'string') {
|
|
153
|
-
pos += dst.write(buf, pos)
|
|
154
|
-
} else {
|
|
155
|
-
pos += buf.copy(dst, pos)
|
|
156
|
-
}
|
|
157
|
-
}
|
|
158
|
-
return pos
|
|
149
|
+
maxLen = 0
|
|
150
|
+
for (const buf of args) {
|
|
151
|
+
maxLen += Buffer.byteLength(buf)
|
|
159
152
|
}
|
|
153
|
+
|
|
154
|
+
fn = defaultWrite
|
|
155
|
+
|
|
160
156
|
opaque = args
|
|
161
157
|
}
|
|
162
158
|
|
|
163
159
|
while (!_tryWrite(maxLen, fn, opaque)) {
|
|
160
|
+
// TODO (fix): Async? Warn? Timeout?
|
|
164
161
|
Atomics.wait(state, READ_INDEX, readPos)
|
|
165
162
|
}
|
|
166
163
|
}
|