Sha256: dba282c3ff703f878b3b9232247168468a4b1f982288038940b4a87692b235bd

Contents?: true

Size: 859 Bytes

Versions: 25

Compression:

Stored size: 859 Bytes

Contents

'use strict';
const tls = require('tls');

module.exports = (options = {}, connect = tls.connect) => new Promise((resolve, reject) => {
	let timeout = false;

	let socket;

	const callback = async () => {
		await socketPromise;

		socket.off('timeout', onTimeout);
		socket.off('error', reject);

		if (options.resolveSocket) {
			resolve({alpnProtocol: socket.alpnProtocol, socket, timeout});

			if (timeout) {
				await Promise.resolve();
				socket.emit('timeout');
			}
		} else {
			socket.destroy();
			resolve({alpnProtocol: socket.alpnProtocol, timeout});
		}
	};

	const onTimeout = async () => {
		timeout = true;
		callback();
	};

	const socketPromise = (async () => {
		try {
			socket = await connect(options, callback);

			socket.on('error', reject);
			socket.once('timeout', onTimeout);
		} catch (error) {
			reject(error);
		}
	})();
});

Version data entries

25 entries across 25 versions & 1 rubygems

Version Path
immosquare-cleaner-0.1.52 node_modules/resolve-alpn/index.js
immosquare-cleaner-0.1.51 node_modules/resolve-alpn/index.js
immosquare-cleaner-0.1.50 node_modules/resolve-alpn/index.js
immosquare-cleaner-0.1.49 node_modules/resolve-alpn/index.js
immosquare-cleaner-0.1.48 node_modules/resolve-alpn/index.js
immosquare-cleaner-0.1.47 node_modules/resolve-alpn/index.js
immosquare-cleaner-0.1.46 node_modules/resolve-alpn/index.js
immosquare-cleaner-0.1.45 node_modules/resolve-alpn/index.js
immosquare-cleaner-0.1.44 node_modules/resolve-alpn/index.js
immosquare-cleaner-0.1.43 node_modules/resolve-alpn/index.js
immosquare-cleaner-0.1.42 node_modules/resolve-alpn/index.js
immosquare-cleaner-0.1.41 node_modules/resolve-alpn/index.js
immosquare-cleaner-0.1.40 node_modules/resolve-alpn/index.js
immosquare-cleaner-0.1.39 node_modules/resolve-alpn/index.js
immosquare-cleaner-0.1.38 node_modules/resolve-alpn/index.js
immosquare-cleaner-0.1.32 node_modules/resolve-alpn/index.js
immosquare-cleaner-0.1.31 node_modules/resolve-alpn/index.js
immosquare-cleaner-0.1.30 node_modules/resolve-alpn/index.js
immosquare-cleaner-0.1.29 node_modules/resolve-alpn/index.js
immosquare-cleaner-0.1.28 node_modules/resolve-alpn/index.js