diff --git a/src/lib/readable-stream/byte-stream-controller.ts b/src/lib/readable-stream/byte-stream-controller.ts index 3d11bbb..3a171ff 100644 --- a/src/lib/readable-stream/byte-stream-controller.ts +++ b/src/lib/readable-stream/byte-stream-controller.ts @@ -996,18 +996,12 @@ export function SetUpReadableByteStreamControllerFromUnderlyingSource( const controller: ReadableByteStreamController = Object.create(ReadableByteStreamController.prototype); let startAlgorithm: () => void | PromiseLike = () => undefined; - let pullAlgorithm: () => Promise = () => promiseResolvedWith(undefined); - let cancelAlgorithm: (reason: any) => Promise = () => promiseResolvedWith(undefined); + let pullAlgorithm: () => Promise = underlyingByteSource.pull !== undefined ? () => underlyingByteSource.pull!(controller) : () => promiseResolvedWith(undefined); + let cancelAlgorithm: (reason: any) => Promise = underlyingByteSource.cancel !== undefined ? reason => underlyingByteSource.cancel!(reason) : () => promiseResolvedWith(undefined); if (underlyingByteSource.start !== undefined) { startAlgorithm = () => underlyingByteSource.start!(controller); } - if (underlyingByteSource.pull !== undefined) { - pullAlgorithm = () => underlyingByteSource.pull!(controller); - } - if (underlyingByteSource.cancel !== undefined) { - cancelAlgorithm = reason => underlyingByteSource.cancel!(reason); - } const autoAllocateChunkSize = underlyingByteSource.autoAllocateChunkSize; if (autoAllocateChunkSize === 0) { diff --git a/src/lib/readable-stream/default-controller.ts b/src/lib/readable-stream/default-controller.ts index 7f1d200..824cd27 100644 --- a/src/lib/readable-stream/default-controller.ts +++ b/src/lib/readable-stream/default-controller.ts @@ -375,18 +375,12 @@ export function SetUpReadableStreamDefaultControllerFromUnderlyingSource( const controller: ReadableStreamDefaultController = Object.create(ReadableStreamDefaultController.prototype); let startAlgorithm: () => void | PromiseLike = () => undefined; - let pullAlgorithm: () => Promise = () => promiseResolvedWith(undefined); - let cancelAlgorithm: (reason: any) => Promise = () => promiseResolvedWith(undefined); + let pullAlgorithm: () => Promise = underlyingSource.pull !== undefined ? () => underlyingSource.pull!(controller) : () => promiseResolvedWith(undefined); + let cancelAlgorithm: (reason: any) => Promise = underlyingSource.cancel !== undefined ? reason => underlyingSource.cancel!(reason) : () => promiseResolvedWith(undefined); if (underlyingSource.start !== undefined) { startAlgorithm = () => underlyingSource.start!(controller); } - if (underlyingSource.pull !== undefined) { - pullAlgorithm = () => underlyingSource.pull!(controller); - } - if (underlyingSource.cancel !== undefined) { - cancelAlgorithm = reason => underlyingSource.cancel!(reason); - } SetUpReadableStreamDefaultController( stream, controller, startAlgorithm, pullAlgorithm, cancelAlgorithm, highWaterMark, sizeAlgorithm