@@ -217,12 +217,19 @@ function transformWithCancel(customCancel) {
217
217
218
218
/**
219
219
* Transform a stream using helper functions which are called on each chunk, and on stream close, respectively.
220
+ * Takes an optional queuing strategy for the resulting readable stream;
221
+ * see https://developer.mozilla.org/en-US/docs/Web/API/ReadableStream/ReadableStream#queuingstrategy.
222
+ * By default, the queueing strategy is non-buffering. When the `process`
223
+ * function is asynchronous, it may be useful to pass a buffering
224
+ * queuing strategy to enable multiple chunks to be processed in parallel;
225
+ * e.g. pass `{ highWaterMark: 4 }` to process up to 4 chunks in parallel.
220
226
* @param {ReadableStream|Uint8array|String } input
221
227
* @param {Function } process
222
228
* @param {Function } finish
229
+ * @param {Object } queuingStrategy
223
230
* @returns {ReadableStream|Uint8array|String }
224
231
*/
225
- function transform ( input , process = ( ) => undefined , finish = ( ) => undefined ) {
232
+ function transform ( input , process = ( ) => undefined , finish = ( ) => undefined , queuingStrategy = { highWaterMark : 0 } ) {
226
233
if ( isArrayStream ( input ) ) {
227
234
const output = new ArrayStream ( ) ;
228
235
( async ( ) => {
@@ -277,7 +284,7 @@ function transform(input, process = () => undefined, finish = () => undefined) {
277
284
async cancel ( reason ) {
278
285
await reader . cancel ( reason ) ;
279
286
}
280
- } , { highWaterMark : 0 } ) ;
287
+ } , queuingStrategy ) ;
281
288
}
282
289
const result1 = process ( input ) ;
283
290
const result2 = finish ( ) ;
0 commit comments