UNPKG

paxjs-promise

Version:
1 lines 1.13 kB
Promise&&(Promise.delay=function(r,t){return void 0===r||r<0?Promise.resolve(t):t instanceof Promise?t.then(function(t){return new Promise(function(e){setTimeout(e,r,t)})}):new Promise(function(e){setTimeout(e,r,t)})},Promise.prototype.delay=function(r){return this.then(function(t){return void 0===r||r<0?t:new Promise(function(e){setTimeout(function(){e(t)},r)})})}),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(i){var e;return null===i||"object"!=typeof i||!i.min&&!i.max?this:i.min>i.max?Promise.reject(new Promise.TimeError("operation max time can't be less than min time")):(e=0<=i.min?Promise.all([this,new Promise(function(e){setTimeout(e,i.min)})]).then(function(e){return e[0]}):this,0<=i.max?new Promise(function(t,r){var o=setTimeout(function(){r(new Promise.TimeError(i.timeoutMessage||"operation timed out"))},i.max);e.then(function(e){clearTimeout(o),t(e)}).catch(function(e){clearTimeout(o),r(e)})}):e)});