UNPKG

cli-engine

Version:
32 lines (28 loc) 713 B
'use strict'; Object.defineProperty(exports, "__esModule", { value: true }); exports.compare = compare; exports.wait = wait; exports.timeout = timeout; const debug = require('debug')('util'); function compare(...props) { return (a, b) => { for (let prop of props) { if (a[prop] === undefined) return -1; if (b[prop] === undefined) return 1; if (a[prop] < b[prop]) return -1; if (a[prop] > b[prop]) return 1; } return 0; }; } function wait(ms, unref = false) { return new Promise(resolve => { let t = setTimeout(resolve, ms); if (unref) t.unref(); }); } function timeout(p, ms) { return Promise.race([p, wait(ms, true).then(() => debug('timed out'))]); }