UNPKG

paxjs-promise

Version:
1 lines 764 B
Promise&&(Promise.TimeError=function(e){this.message=e,this.name="TimeError",Error.captureStackTrace?Error.captureStackTrace(this,this.constructor):Error.call(this)},Promise.TimeError.prototype=Object.create(Error.prototype),Promise.prototype.time=function(o){var e;return null===o||"object"!=typeof o||!o.min&&!o.max?this:o.min>o.max?Promise.reject(new Promise.TimeError("operation max time can't be less than min time")):(e=0<=o.min?Promise.all([this,new Promise(function(e){setTimeout(e,o.min)})]).then(function(e){return e[0]}):this,0<=o.max?new Promise(function(r,t){var i=setTimeout(function(){t(new Promise.TimeError(o.timeoutMessage||"operation timed out"))},o.max);e.then(function(e){clearTimeout(i),r(e)}).catch(function(e){clearTimeout(i),t(e)})}):e)});