@abtnode/util
Advanced tools
Comparing version 1.3.5 to 1.3.6
@@ -186,3 +186,3 @@ const NODE_SERVICES = Object.freeze({ | ||
// Service Gateway | ||
DEFAULT_ROUTER_PROVIDER: 'none', | ||
ROUTER_PROVIDER_NONE: 'none', | ||
DOMAIN_FOR_IP_SITE: '', | ||
@@ -189,0 +189,0 @@ DOMAIN_FOR_IP_SITE_REGEXP: `~^\\d+.\\d+.\\d+.\\d+$`, // eslint-disable-line |
@@ -9,6 +9,6 @@ const net = require('net'); | ||
const dial = (port) => | ||
const dial = (host, port) => | ||
new Promise((resolve, reject) => { | ||
const socket = net.connect({ | ||
host: '127.0.0.1', | ||
host: host || '127.0.0.1', | ||
port, | ||
@@ -27,6 +27,6 @@ }); | ||
const ensureStarted = async (port, timeout = 10 * ONE_SECOND, elapse = 0) => { | ||
const ensureStarted = async ({ host, port, timeout = 10 * ONE_SECOND, elapse = 0 }) => { | ||
const startTime = Date.now(); | ||
try { | ||
await dial(port); | ||
await dial(host, port); | ||
debug('ping if started', { port }); | ||
@@ -46,7 +46,7 @@ return true; | ||
return ensureStarted(port, timeout, spend); | ||
return ensureStarted({ host, port, timeout, elapse: spend }); | ||
} | ||
}; | ||
const ensureHealthy = async ({ port, minConsecutiveTime = 5 * ONE_SECOND }) => { | ||
const ensureHealthy = async ({ host, port, minConsecutiveTime = 5 * ONE_SECOND }) => { | ||
const checkInterval = 100; // ms | ||
@@ -59,3 +59,3 @@ const minCheckTimes = Math.ceil(minConsecutiveTime / checkInterval); | ||
debug('ping if healthy', { port }); | ||
await dial(port); | ||
await dial(host, port); | ||
await sleep(checkInterval); | ||
@@ -65,3 +65,8 @@ } | ||
module.exports = async ({ port, timeout = 10 * ONE_SECOND, minConsecutiveTime = 5 * ONE_SECOND }) => { | ||
module.exports = async ({ | ||
host = '127.0.0.1', | ||
port, | ||
timeout = 10 * ONE_SECOND, | ||
minConsecutiveTime = 5 * ONE_SECOND, | ||
}) => { | ||
debug('ensure endpoint healthy', { port, minConsecutiveTime }); | ||
@@ -74,5 +79,5 @@ | ||
return tryWithTimeout(async () => { | ||
await ensureStarted(port, timeout - minConsecutiveTime); | ||
await ensureHealthy({ port, minConsecutiveTime }); | ||
await ensureStarted({ host, port, timeout: timeout - minConsecutiveTime }); | ||
await ensureHealthy({ host, port, minConsecutiveTime }); | ||
}, timeout); | ||
}; |
@@ -6,3 +6,3 @@ { | ||
}, | ||
"version": "1.3.5", | ||
"version": "1.3.6", | ||
"description": "ArcBlock's JavaScript utility", | ||
@@ -51,3 +51,3 @@ "main": "lib/index.js", | ||
}, | ||
"gitHead": "46d5847cea5c9a3cf15c572346cf3a1626a3c001" | ||
"gitHead": "71de63c9a036c1dad87339d8c2d955cfb58aff66" | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
29800
883