%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /usr/share/nodejs/http2-wrapper/source/utils/
Upload File :
Create Path :
Current File : //usr/share/nodejs/http2-wrapper/source/utils/delay-async-destroy.js

'use strict';

module.exports = stream => {
	if (stream.listenerCount('error') !== 0) {
		return;
	}

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

Zerion Mini Shell 1.0