(fn)
| 209 | }; |
| 210 | |
| 211 | function fromAsyncGen(fn) { |
| 212 | let { promise, resolve } = PromiseWithResolvers(); |
| 213 | const ac = new AbortController(); |
| 214 | const signal = ac.signal; |
| 215 | const value = fn(async function*() { |
| 216 | while (true) { |
| 217 | const _promise = promise; |
| 218 | promise = null; |
| 219 | const { chunk, done, cb } = await _promise; |
| 220 | process.nextTick(cb); |
| 221 | if (done) return; |
| 222 | if (signal.aborted) |
| 223 | throw new AbortError(undefined, { cause: signal.reason }); |
| 224 | ({ promise, resolve } = PromiseWithResolvers()); |
| 225 | yield chunk; |
| 226 | } |
| 227 | }(), { signal }); |
| 228 | |
| 229 | return { |
| 230 | value, |
| 231 | write(chunk, encoding, cb) { |
| 232 | const _resolve = resolve; |
| 233 | resolve = null; |
| 234 | _resolve({ __proto__: null, chunk, done: false, cb }); |
| 235 | }, |
| 236 | final(cb) { |
| 237 | const _resolve = resolve; |
| 238 | resolve = null; |
| 239 | _resolve({ __proto__: null, done: true, cb }); |
| 240 | }, |
| 241 | destroy(err, cb) { |
| 242 | ac.abort(err); |
| 243 | |
| 244 | // If the source async iterator is waiting for the next write/final |
| 245 | // signal, unblock it so the readable side can observe the abort and |
| 246 | // finish destroying. |
| 247 | if (resolve !== null) { |
| 248 | const _resolve = resolve; |
| 249 | resolve = null; |
| 250 | _resolve({ __proto__: null, done: true, cb() {} }); |
| 251 | } |
| 252 | |
| 253 | cb(err); |
| 254 | }, |
| 255 | }; |
| 256 | } |
| 257 | |
| 258 | function _duplexify(pair) { |
| 259 | const r = pair.readable && typeof pair.readable.read !== 'function' ? |
no test coverage detected
searching dependent graphs…