Init
This commit is contained in:
33
node_modules/http2-wrapper/source/utils/delay-async-destroy.js
generated
vendored
Normal file
33
node_modules/http2-wrapper/source/utils/delay-async-destroy.js
generated
vendored
Normal file
@ -0,0 +1,33 @@
|
||||
'use strict';
|
||||
|
||||
module.exports = stream => {
|
||||
if (stream.listenerCount('error') !== 0) {
|
||||
return stream;
|
||||
}
|
||||
|
||||
stream.__destroy = stream._destroy;
|
||||
stream._destroy = (...args) => {
|
||||
const callback = args.pop();
|
||||
|
||||
stream.__destroy(...args, async error => {
|
||||
await Promise.resolve();
|
||||
callback(error);
|
||||
});
|
||||
};
|
||||
|
||||
const onError = error => {
|
||||
// eslint-disable-next-line promise/prefer-await-to-then
|
||||
Promise.resolve().then(() => {
|
||||
stream.emit('error', error);
|
||||
});
|
||||
};
|
||||
|
||||
stream.once('error', onError);
|
||||
|
||||
// eslint-disable-next-line promise/prefer-await-to-then
|
||||
Promise.resolve().then(() => {
|
||||
stream.off('error', onError);
|
||||
});
|
||||
|
||||
return stream;
|
||||
};
|
||||
Reference in New Issue
Block a user