UNPKG

@vtex/api

Version:
32 lines (31 loc) 1.05 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.HttpAgentSingleton = void 0; const agents_1 = require("../../agents"); class HttpAgentSingleton { static getHttpAgent() { if (!HttpAgentSingleton.httpAgent) { HttpAgentSingleton.httpAgent = (0, agents_1.createHttpAgent)(); } return HttpAgentSingleton.httpAgent; } static httpAgentStats() { const sockets = HttpAgentSingleton.count(HttpAgentSingleton.httpAgent.sockets); const freeSockets = HttpAgentSingleton.count(HttpAgentSingleton.httpAgent.freeSockets); const pendingRequests = HttpAgentSingleton.count(HttpAgentSingleton.httpAgent.requests); return { freeSockets, pendingRequests, sockets, }; } static count(obj) { try { return Object.values(obj).reduce((acc, val) => acc += val.length, 0); } catch (_) { return 0; } } } exports.HttpAgentSingleton = HttpAgentSingleton;