"use strict";
// Inspiration from https://github.com/sindresorhus/is-port-reachable/blob/main/index.js
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.isPortReachable = void 0;
const node_net_1 = __importDefault(require("node:net"));
/**
 * Checks if a port at a given host can be reached
 * @returns boolean
 */
const isPortReachable = async ({ host, port, timeout = 1000, }) => {
    const promise = new Promise((resolve, reject) => {
        const socket = new node_net_1.default.Socket();
        const onError = () => {
            socket.destroy();
            reject();
        };
        socket.setTimeout(timeout);
        socket.once('error', onError);
        socket.once('timeout', onError);
        socket.connect(port, host, () => {
            socket.end();
            resolve();
        });
    });
    try {
        await promise;
        return true;
    }
    catch {
        return false;
    }
};
exports.isPortReachable = isPortReachable;
//# sourceMappingURL=isPortReachable.js.map