From 411b626149ef0ffa1664880ad4d52bb96a8f8099 Mon Sep 17 00:00:00 2001 From: Daniel Huigens Date: Thu, 14 Jun 2018 12:18:18 +0200 Subject: [PATCH] Work around timing difference between Chrome and polyfill When piping a stream to a writable stream and erroring that, the input (readable) stream only gets cancelled after pipeTo() returns in Chrome. --- src/stream.js | 7 ++++--- test/unittests.js | 6 +++--- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/src/stream.js b/src/stream.js index 3d028df4..c6177768 100644 --- a/src/stream.js +++ b/src/stream.js @@ -1,8 +1,8 @@ import util from './util'; -// if (typeof TransformStream === 'undefined') { - Object.assign(typeof window !== 'undefined' ? window : global, require('@mattiasbuelens/web-streams-polyfill')); -// } +if (typeof TransformStream === 'undefined') { + require('@mattiasbuelens/web-streams-polyfill'); +} const nodeStream = util.getNodeStream(); @@ -130,6 +130,7 @@ function transformPair(input, fn) { const outgoing = transformWithCancel(async function() { incomingTransformController.error(new Error('Readable side was canceled.')); await pipeDonePromise; + await new Promise(setTimeout); }); fn(incoming.readable, outgoing.writable); return outgoing.readable; diff --git a/test/unittests.js b/test/unittests.js index b2d10619..9359c60b 100644 --- a/test/unittests.js +++ b/test/unittests.js @@ -5,9 +5,9 @@ if (typeof Symbol === 'undefined') { if (typeof Promise === 'undefined') { require('core-js/fn/promise'); } -// if (typeof TransformStream === 'undefined') { - Object.assign(typeof window !== 'undefined' ? window : global, require('@mattiasbuelens/web-streams-polyfill')); -// } +if (typeof TransformStream === 'undefined') { + require('@mattiasbuelens/web-streams-polyfill'); +} (typeof window !== 'undefined' ? window : global).resolves = function(val) { return new Promise(function(res) { res(val); });