UNPKG

@splitsoftware/splitio-commons

Version:
21 lines (20 loc) 637 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.timeout = void 0; function timeout(ms, promise) { if (ms < 1) return promise; return new Promise(function (resolve, reject) { var tid = setTimeout(function () { reject(new Error("Operation timed out because it exceeded the configured time limit of ".concat(ms, " ms."))); }, ms); promise.then(function (res) { clearTimeout(tid); resolve(res); }, function (err) { clearTimeout(tid); reject(err); }); }); } exports.timeout = timeout;