()
| 296 | } |
| 297 | |
| 298 | #pullFromSource() { |
| 299 | if (this.#sourceExhausted || this.#cancelled) { |
| 300 | return PromiseResolve(); |
| 301 | } |
| 302 | |
| 303 | if (this.#pulling) { |
| 304 | const { promise, resolve } = PromiseWithResolvers(); |
| 305 | ArrayPrototypePush(this.#pullWaiters, resolve); |
| 306 | return promise; |
| 307 | } |
| 308 | |
| 309 | this.#pulling = true; |
| 310 | |
| 311 | return (async () => { |
| 312 | try { |
| 313 | if (!this.#sourceIterator) { |
| 314 | if (isAsyncIterable(this.#source)) { |
| 315 | this.#sourceIterator = |
| 316 | this.#source[SymbolAsyncIterator](); |
| 317 | } else if (isSyncIterable(this.#source)) { |
| 318 | const syncIterator = |
| 319 | this.#source[SymbolIterator](); |
| 320 | this.#sourceIterator = { |
| 321 | __proto__: null, |
| 322 | async next() { |
| 323 | return syncIterator.next(); |
| 324 | }, |
| 325 | async return() { |
| 326 | return syncIterator.return?.() ?? |
| 327 | { __proto__: null, done: true, value: undefined }; |
| 328 | }, |
| 329 | }; |
| 330 | } else { |
| 331 | throw new ERR_INVALID_ARG_TYPE( |
| 332 | 'source', ['AsyncIterable', 'Iterable'], this.#source); |
| 333 | } |
| 334 | } |
| 335 | |
| 336 | const result = await this.#sourceIterator.next(); |
| 337 | |
| 338 | if (result.done) { |
| 339 | this.#sourceExhausted = true; |
| 340 | } else { |
| 341 | this.#buffer.push(result.value); |
| 342 | } |
| 343 | } catch (error) { |
| 344 | this.#sourceError = wrapError(error); |
| 345 | this.#sourceExhausted = true; |
| 346 | } finally { |
| 347 | this.#pulling = false; |
| 348 | for (let i = 0; i < this.#pullWaiters.length; i++) { |
| 349 | this.#pullWaiters[i](); |
| 350 | } |
| 351 | this.#pullWaiters = []; |
| 352 | } |
| 353 | })(); |
| 354 | } |
| 355 |
no test coverage detected