diff options
Diffstat (limited to 'includes/external/addressbook/node_modules/http2-wrapper/source/utils/delay-async-destroy.js')
-rw-r--r-- | includes/external/addressbook/node_modules/http2-wrapper/source/utils/delay-async-destroy.js | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/includes/external/addressbook/node_modules/http2-wrapper/source/utils/delay-async-destroy.js b/includes/external/addressbook/node_modules/http2-wrapper/source/utils/delay-async-destroy.js new file mode 100644 index 0000000..53d81cf --- /dev/null +++ b/includes/external/addressbook/node_modules/http2-wrapper/source/utils/delay-async-destroy.js @@ -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; +}; |