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.
This commit is contained in:
Daniel Huigens 2018-06-14 12:18:18 +02:00
parent 55fd292fba
commit 411b626149
2 changed files with 7 additions and 6 deletions

View File

@ -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;

View File

@ -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); });