mybase 1.0.39 → 1.0.40
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/mybase.js +19 -1
- package/package.json +1 -1
package/mybase.js
CHANGED
|
@@ -447,6 +447,22 @@ function validUUID4(uuid) {
|
|
|
447
447
|
return new RegExp(/^[0-9A-F]{8}-[0-9A-F]{4}-[4][0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$/i).test(uuid)
|
|
448
448
|
}
|
|
449
449
|
|
|
450
|
+
function promiseTimeout(ms, promise) {
|
|
451
|
+
// Create a promise that rejects in <ms> milliseconds
|
|
452
|
+
let timeout = new Promise((resolve, reject) => {
|
|
453
|
+
let id = setTimeout(() => {
|
|
454
|
+
clearTimeout(id);
|
|
455
|
+
reject('TIMEDOUT')
|
|
456
|
+
}, ms)
|
|
457
|
+
})
|
|
458
|
+
|
|
459
|
+
// Returns a race between our timeout and the passed in promise
|
|
460
|
+
return Promise.race([
|
|
461
|
+
promise,
|
|
462
|
+
timeout
|
|
463
|
+
])
|
|
464
|
+
}
|
|
465
|
+
|
|
450
466
|
async function portCheck_tcp (port, {timeout = 1000, host='127.0.0.1'} = {}) {
|
|
451
467
|
const promise = new Promise(((resolve, reject) => {
|
|
452
468
|
const socket = new net.Socket();
|
|
@@ -563,5 +579,7 @@ module.exports = {
|
|
|
563
579
|
portCheck_tcp,
|
|
564
580
|
asJSON,
|
|
565
581
|
ensureProperty,
|
|
566
|
-
arrayRandomItem
|
|
582
|
+
arrayRandomItem,
|
|
583
|
+
promiseTimeout
|
|
584
|
+
|
|
567
585
|
}
|