* Read values a chunk at a time from the underlying iterable. Once a full batch is read (or there * aren't enough values to make a full batch), all of the batch's values are yielded before the * next batch is read. * * This is useful for triggering groups of asynchronous tasks via Promis
(size: number)
| 55 | * @returns {Stream} A new Stream that gets its values from this Stream. |
| 56 | */ |
| 57 | batch(size: number) { |
| 58 | return new Stream((function* () { |
| 59 | const b = []; |
| 60 | try { |
| 61 | // @ts-ignore |
| 62 | for (const v of this) { |
| 63 | Promise.resolve(v).catch(() => {}); // Suppress unhandled rejection errors. |
| 64 | b.push(v); |
| 65 | if (b.length < size) continue; |
| 66 | while (b.length) yield b.shift(); |
| 67 | } |
| 68 | while (b.length) yield b.shift(); |
| 69 | } finally { |
| 70 | for (const v of b) Promise.resolve(v).then(() => {}); // Un-suppress unhandled rejections. |
| 71 | } |
| 72 | }).call(this)); |
| 73 | } |
| 74 | |
| 75 | /** |
| 76 | * Pre-fetch a certain number of values from the underlying iterable before yielding the first |
no test coverage detected