Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

promise-toolbox

Package Overview
Dependencies
Maintainers
2
Versions
43
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

promise-toolbox - npm Package Compare versions

Comparing version 0.6.0 to 0.7.0

2

dist/index.js

@@ -1,2 +0,2 @@

'use strict';Object.defineProperty(exports,'__esModule',{value:!0});exports.TimeoutError=exports.promisifyAll=exports.promisify=exports.finally=exports.fromCallback=exports.forOwn=exports.forIterable=exports.forIn=exports.forEach=exports.forArray=exports.makeAsyncIterator=exports.defer=exports.cancellable=exports.nodeify=exports.isPromise=void 0;var _typeof='function'==typeof Symbol&&'symbol'==typeof Symbol.iterator?function(obj){return typeof obj}:function(obj){return obj&&'function'==typeof Symbol&&obj.constructor===Symbol&&obj!==Symbol.prototype?'symbol':typeof obj};exports.all=all;exports.asCallback=asCallback;exports.catchPlus=catchPlus;exports.delay=delay;exports.join=join;exports.lastly=lastly;exports.reflect=reflect;exports.settle=settle;exports.some=some;exports.tap=tap;exports.timeout=timeout;exports.unpromisify=unpromisify;var _makeError=require('make-error');function _classCallCheck(instance,Constructor){if(!(instance instanceof Constructor))throw new TypeError('Cannot call a class as a function')}function _possibleConstructorReturn(self,call){if(!self)throw new ReferenceError('this hasn\'t been initialised - super() hasn\'t been called');return call&&('object'==typeof call||'function'==typeof call)?call:self}function _inherits(subClass,superClass){if('function'!=typeof superClass&&null!==superClass)throw new TypeError('Super expression must either be null or a function, not '+typeof superClass);subClass.prototype=Object.create(superClass&&superClass.prototype,{constructor:{value:subClass,enumerable:!1,writable:!0,configurable:!0}}),superClass&&(Object.setPrototypeOf?Object.setPrototypeOf(subClass,superClass):subClass.__proto__=superClass)}if('function'!=typeof Promise||'function'!=typeof Promise.reject||'function'!=typeof Promise.resolve)throw new Error('a standard Promise implementation is required (https://github.com/JsCommunity/promise-toolbox#usage)');var _endsWith=function _endsWith(a,b){var c=2<arguments.length&&void 0!==arguments[2]?arguments[2]:a.length;return c-=b.length,0<=c&&a.indexOf(b,c)===c},_isArray=Array.isArray||function(a){return a instanceof Array},_isLength=function _isLength(a){return'number'==typeof a&&0<=a&&a<1/0&&Math.floor(a)===a},_isArrayLike=function _isArrayLike(a){return a&&'function'!=typeof a&&_isLength(a.length)},_isIterable='function'==typeof Symbol?function(a){return a&&'function'==typeof a[Symbol.iterator]}:function(){return!1},_noop=function _noop(){},_forArray=function _forArray(a,b){var c=a.length;for(var d=0;d<c;++d)b(a[d],d,a)},_forIn=function _forIn(a,b){for(var c in a)b(a[c],c,a)},_forIterable=function _forIterable(a,b){for(var c=a[Symbol.iterator](),d=void 0;!(d=c.next()).done;)b(d.value,null,a)},hasOwnProperty=Object.prototype.hasOwnProperty,_forOwn=function _forOwn(a,b){for(var c in a)hasOwnProperty.call(a,c)&&b(a[c],c,a)},_forEach=function _forEach(a,b){return _isArray(a)?_forArray(a,b):_isIterable(a)?_forIterable(a,b):_isArrayLike(a)?_forArray(a,b):_forOwn(a,b)},_map=function _map(a,b){var c=_isArrayLike(a)?Array(a.length):{};return b&&_forEach(a,function(d,e){c[e]=b(d,e,a)}),c};var isPromise=exports.isPromise=function isPromise(a){return null!=a&&'function'==typeof a.then};var _makeAsyncIterator=function _makeAsyncIterator(a){return function(b,c){var d=Promise.resolve();return a(b,function(e,g){d=isPromise(e)?d.then(function(){return e.then(function(h){return c(h,g,b)})}):d.then(function(){return c(e,g,b)})}),d}},_wrap=function _wrap(a){return isPromise(a)?a:Promise.resolve(a)},_wrapCall=function _wrapCall(a,b,c){try{return _wrap(a.apply(c,b))}catch(d){return Promise.reject(d)}},_all=function _all(a,b){return new Promise(function(c,d){var e=_map(a,b),g=1,h=function h(){if(0==--g){var l=e;e=null,c(l)}},j=function j(l,m){e&&(e[m]=l,h())},k=function k(l){e&&(e=null,d(l))};_forEach(b?e:a,function(l,m){++g,isPromise(l)?l.then(function(o){return j(o,m)},k):j(l,m)}),h()})};function all(a){return _wrap(this).then(function(b){return _all(b,a)})}function asCallback(a){return a&&this.then(function(b){return a(null,b)},function(b){return a(b)}).then(null,_noop),this}exports.nodeify=asCallback;var cancellable=exports.cancellable=function cancellable(a,b,c){function d(){var h=void 0,j=new Promise(function(l,m){h=m});j.then(null,_noop);for(var _len=arguments.length,g=Array(_len),_key=0;_key<_len;_key++)g[_key]=arguments[_key];var k=e.call.apply(e,[this,j].concat(g));return k.cancel=h,k}var e=c?c.value:a;return c?(c.value=d,c):d};var _isOperationalError=function _isOperationalError(a){return!(a instanceof ReferenceError||a instanceof SyntaxError||a instanceof TypeError)},_errorWrapper={error:null},_tryCatch=function _tryCatch(a){try{return a()}catch(b){return _errorWrapper.error=b,_errorWrapper}},_matchError=function _matchError(a,b){return'function'==typeof a?a.prototype instanceof Error?b instanceof a:a(b):'object'==('undefined'==typeof a?'undefined':_typeof(a))?null!=b&&_tryCatch(function(){return _forOwn(a,function(c,d){if(b[d]!==c)throw null})})!==_errorWrapper:void 0};function catchPlus(){var _this=this,a=arguments.length-1,b=void 0;if(0>a||'function'!=typeof(b=arguments[a]))return this;var c=void 0;if(a){c=Array(a);for(var d=0;d<a;++d)c[d]=arguments[d]}return _wrap(this).then(null,function(d){if(c){for(var _e=0;_e<a;++_e)if(_matchError(c[_e],d))return b(d);}else if(_isOperationalError(d))return b(d);return _this})}var defer=exports.defer=function defer(){var a=void 0,b=void 0,c=new Promise(function(d,e){a=d,b=e});return{promise:c,reject:b,resolve:a}};function delay(a){var _this2=this;return isPromise(this)?this.then(function(b){return new Promise(function(c){setTimeout(function(){return c(b)},a)})}):new Promise(function(b){setTimeout(function(){return b(_this2)},a)})}var makeAsyncIterator=exports.makeAsyncIterator=function makeAsyncIterator(a){var b=_makeAsyncIterator(a);return function(c){return _wrap(this).then(function(d){return b(d,c)}).then(_noop)}};var forArray=exports.forArray=makeAsyncIterator(_forArray);var forEach=exports.forEach=makeAsyncIterator(_forEach);var forIn=exports.forIn=makeAsyncIterator(_forIn);var forIterable=exports.forIterable=makeAsyncIterator(_forIterable);var forOwn=exports.forOwn=makeAsyncIterator(_forOwn);var fromCallback=exports.fromCallback=function fromCallback(a){return new Promise(function(b,c){a(function(d,e){return d?c(d):b(e)})})};function join(){var a=arguments.length-1,b=arguments[a],c=void 0;if(0==a)return new Promise(function(d){return d(b())});if(1!=a){c=Array(a);for(var d=0;d<a;++d)c[d]=arguments[d]}else if(!_isArrayLike(c=arguments[0]))return _wrap(c).then(function(d){return b(d)});return _all(c).then(function(d){return b.apply(null,d)})}function lastly(a){var _this3=this;return _wrap(this).then(function(b){return _wrap(a()).then(function(){return _this3})},function(b){return _wrap(a()).then(function(){return _this3})})}exports.finally=lastly;var _setFunctionNameAndLength=function(){var a=Object.defineProperties;try{var b=a(function(){},{length:{value:2},name:{value:'foo'}});if(2===b.length&&'foo'===b.name)return function(c,d,e){return a(c,{length:{configurable:!0,value:e},name:{configurable:!0,value:d}})}}catch(b){}return function(b){return b}}();var promisify=exports.promisify=function promisify(a,b){return _setFunctionNameAndLength(function(){var _this4=this,c=arguments.length,d=Array(c+1);for(var e=0;e<c;++e)d[e]=arguments[e];return new Promise(function(e,g){d[c]=function(h,j){return h?g(h):e(j)},a.apply(b||_this4,d)})},a.name,a.length&&a.length-1)};var _DEFAULT_PALL_MAPPER=function _DEFAULT_PALL_MAPPER(a,b){return!(_endsWith(a,'Sync')||_endsWith(a,'Async'))&&a};var promisifyAll=exports.promisifyAll=function promisifyAll(a){var _ref=1<arguments.length&&void 0!==arguments[1]?arguments[1]:{},_ref$mapper=_ref.mapper,b=void 0===_ref$mapper?_DEFAULT_PALL_MAPPER:_ref$mapper,_ref$target=_ref.target,c=void 0===_ref$target?{}:_ref$target,_ref$context=_ref.context,d=void 0===_ref$context?a:_ref$context;return _forIn(a,function(e,g){var h=void 0;'function'==typeof e&&(h=b(g,e,a))&&(c[h]=promisify(e,d))}),c};var FN_FALSE=function FN_FALSE(){return!1},FN_TRUE=function FN_TRUE(){return!0},_reflectResolution=function(a){return function(b){return{__proto__:a,value:function value(){return b}}}}({isFulfilled:FN_TRUE,isPending:FN_FALSE,isRejected:FN_FALSE,isResolved:FN_TRUE,reason:function reason(){throw new Error('no reason, the promise has resolved')}}),_reflectRejection=function(a){return function(b){return{__proto__:a,reason:function reason(){return b}}}}({isFulfilled:FN_FALSE,isPending:FN_FALSE,isRejected:FN_TRUE,isResolved:FN_FALSE,value:function value(){throw new Error('no value, the promise has rejected')}});function reflect(){return _wrap(this).then(_reflectResolution,_reflectRejection)}function settle(){return all.call(this,function(a){return reflect.call(a)})}var _some=function _some(a,b){return new Promise(function(c,d){var e=[],g=[],h=function h(l){e&&(e.push(l),0==--b&&(c(e),e=g=null))},j=-b,k=function k(l){e&&(g.push(l),0==--j&&(d(g),e=g=null))};_forEach(a,function(l){++j,_wrap(l).then(h,k)})})};function some(a){return _wrap(this).then(function(b){return _some(b,a)})}function tap(a,b){var _this5=this,c=function c(){return _this5};return _wrap(this).then(a&&function(d){return _wrap(a(d)).then(c)},b&&function(d){return _wrap(b(d)).then(c)})}var TimeoutError=exports.TimeoutError=function(_BaseError){function TimeoutError(){return _classCallCheck(this,TimeoutError),_possibleConstructorReturn(this,(TimeoutError.__proto__||Object.getPrototypeOf(TimeoutError)).call(this,'operation timed out'))}return _inherits(TimeoutError,_BaseError),TimeoutError}(_makeError.BaseError);function timeout(a,b){var _this7=this;return new Promise(function(c,d){var e=setTimeout(function(){e=null,'function'==typeof _this7.cancel&&_this7.cancel(),b?c(b()):d(new TimeoutError)},a);_wrap(_this7).then(function(g){null!==e&&clearTimeout(e),c(g)},function(g){null!==e&&clearTimeout(e),d(g)})})}function unpromisify(){var a=this;return _setFunctionNameAndLength(function(){var b=arguments.length-1,c=void 0;if(0>b||'function'!=typeof(c=arguments[b]))throw new Error('missing callback');var d=Array(b);for(var e=0;e<b;++e)d[e]=arguments[e];_wrapCall(a,d,this).then(function(e){return c(null,e)},function(e){return c(e)})},a.name,a.length+1)}
'use strict';Object.defineProperty(exports,'__esModule',{value:!0});exports.TimeoutError=exports.promisifyAll=exports.promisify=exports.finally=exports.fromCallback=exports.forOwn=exports.forIterable=exports.forIn=exports.forEach=exports.forArray=exports.makeAsyncIterator=exports.defer=exports.cancelable=exports.cancellable=exports.CancelToken=exports.Cancel=exports.nodeify=exports.isPromise=void 0;var _typeof='function'==typeof Symbol&&'symbol'==typeof Symbol.iterator?function(obj){return typeof obj}:function(obj){return obj&&'function'==typeof Symbol&&obj.constructor===Symbol&&obj!==Symbol.prototype?'symbol':typeof obj};var _createClass=function(){function defineProperties(target,props){for(var i=0;i<props.length;i++){var descriptor=props[i];descriptor.enumerable=descriptor.enumerable||!1,descriptor.configurable=!0,'value'in descriptor&&(descriptor.writable=!0),Object.defineProperty(target,descriptor.key,descriptor)}}return function(Constructor,protoProps,staticProps){return protoProps&&defineProperties(Constructor.prototype,protoProps),staticProps&&defineProperties(Constructor,staticProps),Constructor}}();exports.all=all;exports.asCallback=asCallback;exports.catchPlus=catchPlus;exports.delay=delay;exports.join=join;exports.lastly=lastly;exports.reflect=reflect;exports.settle=settle;exports.some=some;exports.tap=tap;exports.timeout=timeout;exports.unpromisify=unpromisify;var _makeError=require('make-error');function _possibleConstructorReturn(self,call){if(!self)throw new ReferenceError('this hasn\'t been initialised - super() hasn\'t been called');return call&&('object'==typeof call||'function'==typeof call)?call:self}function _inherits(subClass,superClass){if('function'!=typeof superClass&&null!==superClass)throw new TypeError('Super expression must either be null or a function, not '+typeof superClass);subClass.prototype=Object.create(superClass&&superClass.prototype,{constructor:{value:subClass,enumerable:!1,writable:!0,configurable:!0}}),superClass&&(Object.setPrototypeOf?Object.setPrototypeOf(subClass,superClass):subClass.__proto__=superClass)}function _classCallCheck(instance,Constructor){if(!(instance instanceof Constructor))throw new TypeError('Cannot call a class as a function')}if('function'!=typeof Promise||'function'!=typeof Promise.reject||'function'!=typeof Promise.resolve)throw new Error('a standard Promise implementation is required (https://github.com/JsCommunity/promise-toolbox#usage)');var _endsWith=function _endsWith(a,b){var c=2<arguments.length&&void 0!==arguments[2]?arguments[2]:a.length;return c-=b.length,0<=c&&a.indexOf(b,c)===c},_isArray=Array.isArray||function(a){return a instanceof Array},_isLength=function _isLength(a){return'number'==typeof a&&0<=a&&a<1/0&&Math.floor(a)===a},_isArrayLike=function _isArrayLike(a){return a&&'function'!=typeof a&&_isLength(a.length)},_iteratorSymbol='function'==typeof Symbol&&Symbol.iterator||'@@iterator',_isIterable=function _isIterable(a){return a&&'function'==typeof a[_iteratorSymbol]},_noop=function _noop(){},_forArray=function _forArray(a,b){var c=a.length;for(var d=0;d<c;++d)b(a[d],d,a)},_forIn=function _forIn(a,b){for(var c in a)b(a[c],c,a)},_forIterable=function _forIterable(a,b){for(var c=a[Symbol.iterator](),d=void 0;!(d=c.next()).done;)b(d.value,null,a)},hasOwnProperty=Object.prototype.hasOwnProperty,_forOwn=function _forOwn(a,b){for(var c in a)hasOwnProperty.call(a,c)&&b(a[c],c,a)},_forEach=function _forEach(a,b){return _isArray(a)?_forArray(a,b):_isIterable(a)?_forIterable(a,b):_isArrayLike(a)?_forArray(a,b):_forOwn(a,b)},_map=function _map(a,b){var c=_isArrayLike(a)?Array(a.length):{};return b&&_forEach(a,function(d,e){c[e]=b(d,e,a)}),c};var isPromise=exports.isPromise=function isPromise(a){return null!=a&&'function'==typeof a.then};var _makeAsyncIterator=function _makeAsyncIterator(a){return function(b,c){var d=Promise.resolve();return a(b,function(e,g){d=isPromise(e)?d.then(function(){return e.then(function(h){return c(h,g,b)})}):d.then(function(){return c(e,g,b)})}),d}},_wrap=function _wrap(a){return isPromise(a)?a:Promise.resolve(a)},_wrapCall=function _wrapCall(a,b,c){try{return _wrap(a.apply(c,b))}catch(d){return Promise.reject(d)}},_all=function _all(a,b){return new Promise(function(c,d){var e=_map(a,b),g=1,h=function h(){if(0==--g){var l=e;e=null,c(l)}},j=function j(l,m){e&&(e[m]=l,h())},k=function k(l){e&&(e=null,d(l))};_forEach(b?e:a,function(l,m){++g,isPromise(l)?l.then(function(o){return j(o,m)},k):j(l,m)}),h()})};function all(a){return _wrap(this).then(function(b){return _all(b,a)})}function asCallback(a){return a&&this.then(function(b){return a(null,b)},function(b){return a(b)}).then(null,_noop),this}exports.nodeify=asCallback;var Cancel=exports.Cancel=function(){function Cancel(){var a=0<arguments.length&&void 0!==arguments[0]?arguments[0]:'this action has been canceled';_classCallCheck(this,Cancel),this._message=a}return _createClass(Cancel,[{key:'toString',value:function toString(){return'Cancel: '+this._message}}]),Cancel}();var _toStringTagSymbol='function'==typeof Symbol&&Symbol.toStringTag||'@@toStringTag';var CancelToken=exports.CancelToken=function(){function CancelToken(a){var _this=this;_classCallCheck(this,CancelToken),this._cancel=null,this._promise=null,this._resolve=null;var _b=function b(c){_b=_noop,_this._cancel=new Cancel(c);var d=_this._resolve;d&&(d(),_this._resolve=null)};a(function(c){return _b(c)})}return _createClass(CancelToken,null,[{key:'source',value:function source(){var a=void 0,b=new CancelToken(function(c){a=c});return{cancel:a,token:b}}}]),_createClass(CancelToken,[{key:'throwIfRequested',value:function throwIfRequested(){var a=this._cancel;if(a)throw a}},{key:_toStringTagSymbol,value:function value(){return'CancelToken'}},{key:'promise',get:function get(){var _this2=this,a=this._promise;return a||(this._cancel?a=this._promise=Promise.resolve():a=this._promise=new Promise(function(b){_this2._resolve=b})),a}},{key:'requested',get:function get(){return!!this._cancel}}]),CancelToken}();var cancellable=exports.cancellable=function cancellable(a,b,c){function d(){var g=arguments.length;if(g&&arguments[0]instanceof CancelToken)return e.apply(this,k);var _CancelToken$source=CancelToken.source(),h=_CancelToken$source.cancel,j=_CancelToken$source.token,k=Array(g+1);k[0]=j;for(var m=0;m<g;++m)k[m+1]=arguments[m];var l=e.apply(this,k);return l.cancel=h,l}var e=c?c.value:a;return c?(c.value=d,c):d};exports.cancelable=cancellable;var _isOperationalError=function _isOperationalError(a){return!(a instanceof ReferenceError||a instanceof SyntaxError||a instanceof TypeError)},_errorWrapper={error:null},_tryCatch=function _tryCatch(a){try{return a()}catch(b){return _errorWrapper.error=b,_errorWrapper}},_matchError=function _matchError(a,b){return'function'==typeof a?a.prototype instanceof Error?b instanceof a:a(b):'object'==('undefined'==typeof a?'undefined':_typeof(a))?null!=b&&_tryCatch(function(){return _forOwn(a,function(c,d){if(b[d]!==c)throw null})})!==_errorWrapper:void 0};function catchPlus(){var _this3=this,a=arguments.length-1,b=void 0;if(0>a||'function'!=typeof(b=arguments[a]))return this;var c=void 0;if(a){c=Array(a);for(var d=0;d<a;++d)c[d]=arguments[d]}return _wrap(this).then(null,function(d){if(c){for(var _e=0;_e<a;++_e)if(_matchError(c[_e],d))return b(d);}else if(_isOperationalError(d))return b(d);return _this3})}var defer=exports.defer=function defer(){var a=void 0,b=void 0,c=new Promise(function(d,e){a=d,b=e});return{promise:c,reject:b,resolve:a}};function delay(a){var _this4=this;return isPromise(this)?this.then(function(b){return new Promise(function(c){setTimeout(function(){return c(b)},a)})}):new Promise(function(b){setTimeout(function(){return b(_this4)},a)})}var makeAsyncIterator=exports.makeAsyncIterator=function makeAsyncIterator(a){var b=_makeAsyncIterator(a);return function(c){return _wrap(this).then(function(d){return b(d,c)}).then(_noop)}};var forArray=exports.forArray=makeAsyncIterator(_forArray);var forEach=exports.forEach=makeAsyncIterator(_forEach);var forIn=exports.forIn=makeAsyncIterator(_forIn);var forIterable=exports.forIterable=makeAsyncIterator(_forIterable);var forOwn=exports.forOwn=makeAsyncIterator(_forOwn);var fromCallback=exports.fromCallback=function fromCallback(a){return new Promise(function(b,c){a(function(d,e){return d?c(d):b(e)})})};function join(){var a=arguments.length-1,b=arguments[a],c=void 0;if(0==a)return new Promise(function(d){return d(b())});if(1!=a){c=Array(a);for(var d=0;d<a;++d)c[d]=arguments[d]}else if(!_isArrayLike(c=arguments[0]))return _wrap(c).then(function(d){return b(d)});return _all(c).then(function(d){return b.apply(null,d)})}function lastly(a){var _this5=this;return _wrap(this).then(function(b){return _wrap(a()).then(function(){return _this5})},function(b){return _wrap(a()).then(function(){return _this5})})}exports.finally=lastly;var _setFunctionNameAndLength=function(){var a=Object.defineProperties;try{var b=a(function(){},{length:{value:2},name:{value:'foo'}});if(2===b.length&&'foo'===b.name)return function(c,d,e){return a(c,{length:{configurable:!0,value:e},name:{configurable:!0,value:d}})}}catch(b){}return function(b){return b}}();var promisify=exports.promisify=function promisify(a,b){return _setFunctionNameAndLength(function(){var _this6=this,c=arguments.length,d=Array(c+1);for(var e=0;e<c;++e)d[e]=arguments[e];return new Promise(function(e,g){d[c]=function(h,j){return h?g(h):e(j)},a.apply(b||_this6,d)})},a.name,a.length&&a.length-1)};var _DEFAULT_PALL_MAPPER=function _DEFAULT_PALL_MAPPER(a){return!(_endsWith(a,'Sync')||_endsWith(a,'Async'))&&a};var promisifyAll=exports.promisifyAll=function promisifyAll(a){var _ref=1<arguments.length&&void 0!==arguments[1]?arguments[1]:{},_ref$mapper=_ref.mapper,b=void 0===_ref$mapper?_DEFAULT_PALL_MAPPER:_ref$mapper,_ref$target=_ref.target,c=void 0===_ref$target?{}:_ref$target,_ref$context=_ref.context,d=void 0===_ref$context?a:_ref$context;return _forIn(a,function(e,g){var h=void 0;'function'==typeof e&&(h=b(g,e,a))&&(c[h]=promisify(e,d))}),c};var FN_FALSE=function FN_FALSE(){return!1},FN_TRUE=function FN_TRUE(){return!0},_reflectResolution=function(a){return function(b){return{__proto__:a,value:function value(){return b}}}}({isFulfilled:FN_TRUE,isPending:FN_FALSE,isRejected:FN_FALSE,isResolved:FN_TRUE,reason:function reason(){throw new Error('no reason, the promise has resolved')}}),_reflectRejection=function(a){return function(b){return{__proto__:a,reason:function reason(){return b}}}}({isFulfilled:FN_FALSE,isPending:FN_FALSE,isRejected:FN_TRUE,isResolved:FN_FALSE,value:function value(){throw new Error('no value, the promise has rejected')}});function reflect(){return _wrap(this).then(_reflectResolution,_reflectRejection)}function settle(){return all.call(this,function(a){return reflect.call(a)})}var _some=function _some(a,b){return new Promise(function(c,d){var e=[],g=[],h=function h(l){e&&(e.push(l),0==--b&&(c(e),e=g=null))},j=-b,k=function k(l){e&&(g.push(l),0==--j&&(d(g),e=g=null))};_forEach(a,function(l){++j,_wrap(l).then(h,k)})})};function some(a){return _wrap(this).then(function(b){return _some(b,a)})}function tap(a,b){var _this7=this,c=function c(){return _this7};return _wrap(this).then(a&&function(d){return _wrap(a(d)).then(c)},b&&function(d){return _wrap(b(d)).then(c)})}var TimeoutError=exports.TimeoutError=function(_BaseError){function TimeoutError(){return _classCallCheck(this,TimeoutError),_possibleConstructorReturn(this,(TimeoutError.__proto__||Object.getPrototypeOf(TimeoutError)).call(this,'operation timed out'))}return _inherits(TimeoutError,_BaseError),TimeoutError}(_makeError.BaseError);function timeout(a,b){var _this9=this;return new Promise(function(c,d){var e=setTimeout(function(){if(e=null,'function'==typeof _this9.cancel&&_this9.cancel(),b)try{c(b())}catch(g){d(g)}else d(new TimeoutError)},a);_wrap(_this9).then(function(g){null!==e&&clearTimeout(e),c(g)},function(g){null!==e&&clearTimeout(e),d(g)})})}function unpromisify(){var a=this;return _setFunctionNameAndLength(function(){var b=arguments.length-1,c=void 0;if(0>b||'function'!=typeof(c=arguments[b]))throw new Error('missing callback');var d=Array(b);for(var e=0;e<b;++e)d[e]=arguments[e];_wrapCall(a,d,this).then(function(e){return c(null,e)},function(e){return c(e)})},a.name,a.length+1)}
//# sourceMappingURL=index.js.map

@@ -1,2 +0,2 @@

'use strict';var _slicedToArray=function(){function sliceIterator(arr,i){var _arr=[],_n=!0,_d=!1,_e=void 0;try{for(var _s,_i=arr[Symbol.iterator]();!(_n=(_s=_i.next()).done)&&(_arr.push(_s.value),!(i&&_arr.length===i));_n=!0);}catch(err){_d=!0,_e=err}finally{try{!_n&&_i['return']&&_i['return']()}finally{if(_d)throw _e}}return _arr}return function(arr,i){if(Array.isArray(arr))return arr;if(Symbol.iterator in Object(arr))return sliceIterator(arr,i);throw new TypeError('Invalid attempt to destructure non-iterable instance')}}();var _must=require('must'),_must2=_interopRequireDefault(_must),_makeError=require('make-error'),_makeError2=_interopRequireDefault(_makeError),_sinon=require('sinon'),_sinon2=_interopRequireDefault(_sinon),_=require('./');function _interopRequireDefault(obj){return obj&&obj.__esModule?obj:{default:obj}}describe('all()',function(){it('with array',function(){var _context;return(0,_must2.default)((_context=[Promise.resolve('foo'),'bar'],_.all).call(_context)).to.resolve.to.eql(['foo','bar'])}),it('with object',function(){var _context2;return(0,_must2.default)((_context2={foo:Promise.resolve('foo'),bar:'bar'},_.all).call(_context2)).to.resolve.to.eql({foo:'foo',bar:'bar'})}),it('resolve with empty collection',function(){var _context3;return(0,_must2.default)((_context3=[],_.all).call(_context3)).to.resolve.to.eql([])}),it('rejects first rejection',function(){var _context4;return(0,_must2.default)((_context4=['foo',Promise.reject('bar')],_.all).call(_context4)).to.reject.to.equal('bar')}),it('rejects first rejection (even with pending promises)',function(){var _context5;return(0,_must2.default)((_context5=[new Promise(function(){}),Promise.reject('bar')],_.all).call(_context5)).to.reject.to.equal('bar')})}),describe('catchPlus',function(){var a=function a(b){return b};it('catches errors matching a predicate',function(){var _context6,b=function b(c){return'foo'===c};return Promise.all([(0,_must2.default)((_context6=Promise.reject('foo'),_.catchPlus).call(_context6,b,a)).to.resolve.to.equal('foo'),(0,_must2.default)((_context6=Promise.reject('bar'),_.catchPlus).call(_context6,b,a)).to.reject.to.equal('bar')])}),it('catches errors matching a class',function(){var _context7,b=(0,_makeError2.default)('CustomError1'),c=(0,_makeError2.default)('CustomError2'),d=new b;return Promise.all([(0,_must2.default)((_context7=Promise.reject(d),_.catchPlus).call(_context7,b,a)).to.resolve.to.equal(d),(0,_must2.default)((_context7=Promise.reject(d),_.catchPlus).call(_context7,Error,a)).to.resolve.to.equal(d),(0,_must2.default)((_context7=Promise.reject(d),_.catchPlus).call(_context7,c,a)).to.reject.to.equal(d)])}),it('catches errors matching an object pattern',function(){var _context8,b={foo:0};return Promise.all([(0,_must2.default)((_context8=Promise.reject({foo:0}),_.catchPlus).call(_context8,b,a)).to.resolve.to.be.an.object(),(0,_must2.default)((_context8=Promise.reject({foo:1}),_.catchPlus).call(_context8,b,a)).to.reject.to.be.an.object(),(0,_must2.default)((_context8=Promise.reject({bar:0}),_.catchPlus).call(_context8,b,a)).to.reject.to.be.an.object()])}),it('does not catch programmer errors',function(){var _context9;return Promise.all([(0,_must2.default)((_context9=Promise.reject(new TypeError('')),_.catchPlus).call(_context9,a)).to.reject.to.error(TypeError),(0,_must2.default)((_context9=Promise.reject(new SyntaxError('')),_.catchPlus).call(_context9,a)).to.reject.to.error(SyntaxError),(0,_must2.default)((_context9=Promise.reject(new TypeError('')),_.catchPlus).call(_context9,TypeError,a)).to.resolve.to.error(TypeError)])})}),describe('forArray()',function(){it('iterates over an array of promises',function(){var a=_sinon2.default.spy(),b=[Promise.resolve('foo'),Promise.resolve('bar'),'baz'];return(0,_must2.default)(_.forArray.call(b,a)).to.resolve.to.undefined().then(function(){(0,_must2.default)(a.args).to.eql([['foo',0,b],['bar',1,b],['baz',2,b]])})})}),describe('fromCallback()',function(){it('creates a promise which resolves with value passed to the callback',function(){return(0,_must2.default)((0,_.fromCallback)(function(a){a(null,'foo')})).to.resolve.to.equal('foo')}),it('creates a promise which rejects with reason passed to the callback',function(){return(0,_must2.default)((0,_.fromCallback)(function(a){a('bar')})).to.reject.to.equal('bar')})}),describe('join()',function(){it('calls the callback once promises are resolved',function(){return(0,_.join)(Promise.resolve('foo'),Promise.resolve('bar'),function(a,b){(0,_must2.default)(a).to.equal('foo'),(0,_must2.default)(b).to.equal('bar')})}),it('can takes inputs in an array',function(){return(0,_.join)([Promise.resolve('foo'),Promise.resolve('bar')],function(a,b){(0,_must2.default)(a).to.equal('foo'),(0,_must2.default)(b).to.equal('bar')})}),it('rejects if one promise rejects',function(){return(0,_must2.default)((0,_.join)(Promise.resolve('foo'),Promise.reject('bar'),function(a,b){(0,_must2.default)(a).to.equal('foo'),(0,_must2.default)(b).to.equal('bar')})).to.reject.to.equal('bar')})}),describe('lastly()',function(){it('calls a callback on resolution',function(){var _context10,a={},b=_sinon2.default.spy();return(0,_must2.default)((_context10=Promise.resolve(a),_.lastly).call(_context10,b)).to.resolve.to.equal(a).then(function(){(0,_must2.default)(b.callCount).to.equal(1)})}),it('calls a callback on rejection',function(){var _context11,a={},b=_sinon2.default.spy();return(0,_must2.default)((_context11=Promise.reject(a),_.lastly).call(_context11,b)).to.reject.to.equal(a).then(function(){(0,_must2.default)(b.callCount).to.equal(1)})})}),describe('promisifyAll()',function(){it('returns a new object',function(){var a={},b=(0,_.promisifyAll)(a);(0,_must2.default)(b).to.be.an.object(),(0,_must2.default)(b).to.not.equal(a)}),it('creates promisified version of all functions bound to the original object',function(){var a={foo:function foo(c){c(null,this)}},b=(0,_.promisifyAll)(a);return(0,_must2.default)(b.foo()).to.resolve.to.equal(a)}),it('ignores functions ending with Sync or Async',function(){var a={fooAsync:function fooAsync(){},fooSync:function fooSync(){}},b=_.promisifyAll.call(a);(0,_must2.default)(b).to.not.have.property('foo'),(0,_must2.default)(b).to.not.have.property('fooASync'),(0,_must2.default)(b).to.not.have.property('fooSync')})}),describe('settle()',function(){it('works with arrays',function(){var _context12;return(_context12=[Promise.resolve(42),Math.PI,Promise.reject('fatality')],_.settle).call(_context12).then(function(_ref){var _ref2=_slicedToArray(_ref,3),a=_ref2[0],b=_ref2[1],c=_ref2[2];(0,_must2.default)(a.isFulfilled()).to.equal(!0),(0,_must2.default)(b.isFulfilled()).to.equal(!0),(0,_must2.default)(c.isFulfilled()).to.equal(!1),(0,_must2.default)(a.isResolved()).to.equal(!0),(0,_must2.default)(b.isResolved()).to.equal(!0),(0,_must2.default)(c.isResolved()).to.equal(!1),(0,_must2.default)(a.isRejected()).to.equal(!1),(0,_must2.default)(b.isRejected()).to.equal(!1),(0,_must2.default)(c.isRejected()).to.equal(!0),(0,_must2.default)(a.value()).to.equal(42),(0,_must2.default)(b.value()).to.equal(Math.PI),(0,_must2.default)(c.value.bind(c)).to.throw(),(0,_must2.default)(a.reason.bind(a)).to.throw(),(0,_must2.default)(b.reason.bind(b)).to.throw(),(0,_must2.default)(c.reason()).to.equal('fatality')})}),it('works with objects',function(){var _context13;return(_context13={a:Promise.resolve(42),b:Math.PI,c:Promise.reject('fatality')},_.settle).call(_context13).then(function(_ref3){var a=_ref3.a,b=_ref3.b,c=_ref3.c;(0,_must2.default)(a.isFulfilled()).to.equal(!0),(0,_must2.default)(b.isFulfilled()).to.equal(!0),(0,_must2.default)(c.isFulfilled()).to.equal(!1),(0,_must2.default)(a.isResolved()).to.equal(!0),(0,_must2.default)(b.isResolved()).to.equal(!0),(0,_must2.default)(c.isResolved()).to.equal(!1),(0,_must2.default)(a.isRejected()).to.equal(!1),(0,_must2.default)(b.isRejected()).to.equal(!1),(0,_must2.default)(c.isRejected()).to.equal(!0),(0,_must2.default)(a.value()).to.equal(42),(0,_must2.default)(b.value()).to.equal(Math.PI),(0,_must2.default)(c.value.bind(c)).to.throw(),(0,_must2.default)(a.reason.bind(a)).to.throw(),(0,_must2.default)(b.reason.bind(b)).to.throw(),(0,_must2.default)(c.reason()).to.equal('fatality')})})}),describe('tap(cb)',function(){it('call cb with the resolved value',function(){return new Promise(function(a){var _context14;(_context14=Promise.resolve('value'),_.tap).call(_context14,function(b){(0,_must2.default)(b).to.equal('value'),a()})})}),it('does not call cb if the promise is rejected',function(){var _context15;return(0,_must2.default)((_context15=Promise.reject('reason'),_.tap).call(_context15,function(){return Promise.reject('other reason')})).to.reject.to.equal('reason')}),it('forwards the resolved value',function(){var _context16;return(0,_must2.default)((_context16=Promise.resolve('value'),_.tap).call(_context16,function(){return'other value'})).to.resolve.to.equal('value')}),it('rejects if cb rejects',function(){var _context17;return(0,_must2.default)((_context17=Promise.resolve('value'),_.tap).call(_context17,function(){return Promise.reject('reason')})).to.reject.to.equal('reason')})}),describe('tap(null, cb)',function(){it('call cb with the rejected reason',function(){return new Promise(function(a){var _context18;(_context18=Promise.reject('reason'),_.tap).call(_context18,null,function(b){(0,_must2.default)(b).to.equal('reason'),a()})})}),it('does not call cb if the promise is resolved',function(){var _context19;return(0,_must2.default)((_context19=Promise.resolve('value'),_.tap).call(_context19,null,function(){return Promise.reject('other reason')})).to.resolve.to.equal('value')}),it('forwards the rejected reason',function(){var _context20;return(0,_must2.default)((_context20=Promise.reject('reason'),_.tap).call(_context20,null,function(){return'value'})).to.reject.to.equal('reason')}),it('rejects if cb rejects',function(){var _context21;return(0,_must2.default)((_context21=Promise.reject('reason'),_.tap).call(_context21,null,function(){return Promise.reject('other reason')})).to.reject.to.equal('other reason')})}),describe('timeout()',function(){it('rejects a promise if not settled after a delay',function(){var _context22;return(0,_must2.default)((_context22=new Promise(function(){}),_.timeout).call(_context22,10)).to.reject.to.error(_.TimeoutError)}),it('call the callback if not settled after a delay',function(){var _context23;return(0,_must2.default)((_context23=new Promise(function(){}),_.timeout).call(_context23,10,function(){return'bar'})).to.resolve.to.equal('bar')}),it('forwards the settlement if settled before a delay',function(){var _context24;return Promise.all([(0,_must2.default)((_context24=Promise.resolve('value'),_.timeout).call(_context24,10)).to.resolve.to.equal('value'),(0,_must2.default)((_context24=Promise.reject('reason'),_.timeout).call(_context24,10)).to.reject.to.equal('reason')])})}),describe('unpromisify()',function(){it('forwards the result',function(a){var b=_.unpromisify.call(function(){return Promise.resolve('foo')});b(function(c,d){(0,_must2.default)(c).to.not.exist(),(0,_must2.default)(d).to.equal('foo'),a()})}),it('forwards the error',function(a){var b=_.unpromisify.call(function(){return Promise.reject('foo')});b(function(c){(0,_must2.default)(c).to.equal('foo'),a()})})});
'use strict';var _slicedToArray=function(){function sliceIterator(arr,i){var _arr=[],_n=!0,_d=!1,_e=void 0;try{for(var _s,_i=arr[Symbol.iterator]();!(_n=(_s=_i.next()).done)&&(_arr.push(_s.value),!(i&&_arr.length===i));_n=!0);}catch(err){_d=!0,_e=err}finally{try{!_n&&_i['return']&&_i['return']()}finally{if(_d)throw _e}}return _arr}return function(arr,i){if(Array.isArray(arr))return arr;if(Symbol.iterator in Object(arr))return sliceIterator(arr,i);throw new TypeError('Invalid attempt to destructure non-iterable instance')}}();var _must=require('must'),_must2=_interopRequireDefault(_must),_makeError=require('make-error'),_makeError2=_interopRequireDefault(_makeError),_sinon=require('sinon'),_sinon2=_interopRequireDefault(_sinon),_=require('./');function _interopRequireDefault(obj){return obj&&obj.__esModule?obj:{default:obj}}describe('all()',function(){it('with array',function(){var _context;return(0,_must2.default)((_context=[Promise.resolve('foo'),'bar'],_.all).call(_context)).to.resolve.to.eql(['foo','bar'])}),it('with object',function(){var _context2;return(0,_must2.default)((_context2={foo:Promise.resolve('foo'),bar:'bar'},_.all).call(_context2)).to.resolve.to.eql({foo:'foo',bar:'bar'})}),it('resolve with empty collection',function(){var _context3;return(0,_must2.default)((_context3=[],_.all).call(_context3)).to.resolve.to.eql([])}),it('rejects first rejection',function(){var _context4;return(0,_must2.default)((_context4=['foo',Promise.reject('bar')],_.all).call(_context4)).to.reject.to.equal('bar')}),it('rejects first rejection (even with pending promises)',function(){var _context5;return(0,_must2.default)((_context5=[new Promise(function(){}),Promise.reject('bar')],_.all).call(_context5)).to.reject.to.equal('bar')})}),describe('catchPlus',function(){var a=function a(b){return b};it('catches errors matching a predicate',function(){var _context6,b=function b(c){return'foo'===c};return Promise.all([(0,_must2.default)((_context6=Promise.reject('foo'),_.catchPlus).call(_context6,b,a)).to.resolve.to.equal('foo'),(0,_must2.default)((_context6=Promise.reject('bar'),_.catchPlus).call(_context6,b,a)).to.reject.to.equal('bar')])}),it('catches errors matching a class',function(){var _context7,b=(0,_makeError2.default)('CustomError1'),c=(0,_makeError2.default)('CustomError2'),d=new b;return Promise.all([(0,_must2.default)((_context7=Promise.reject(d),_.catchPlus).call(_context7,b,a)).to.resolve.to.equal(d),(0,_must2.default)((_context7=Promise.reject(d),_.catchPlus).call(_context7,Error,a)).to.resolve.to.equal(d),(0,_must2.default)((_context7=Promise.reject(d),_.catchPlus).call(_context7,c,a)).to.reject.to.equal(d)])}),it('catches errors matching an object pattern',function(){var _context8,b={foo:0};return Promise.all([(0,_must2.default)((_context8=Promise.reject({foo:0}),_.catchPlus).call(_context8,b,a)).to.resolve.to.be.an.object(),(0,_must2.default)((_context8=Promise.reject({foo:1}),_.catchPlus).call(_context8,b,a)).to.reject.to.be.an.object(),(0,_must2.default)((_context8=Promise.reject({bar:0}),_.catchPlus).call(_context8,b,a)).to.reject.to.be.an.object()])}),it('does not catch programmer errors',function(){var _context9;return Promise.all([(0,_must2.default)((_context9=Promise.reject(new TypeError('')),_.catchPlus).call(_context9,a)).to.reject.to.error(TypeError),(0,_must2.default)((_context9=Promise.reject(new SyntaxError('')),_.catchPlus).call(_context9,a)).to.reject.to.error(SyntaxError),(0,_must2.default)((_context9=Promise.reject(new TypeError('')),_.catchPlus).call(_context9,TypeError,a)).to.resolve.to.error(TypeError)])})}),describe('forArray()',function(){it('iterates over an array of promises',function(){var a=_sinon2.default.spy(),b=[Promise.resolve('foo'),Promise.resolve('bar'),'baz'];return(0,_must2.default)(_.forArray.call(b,a)).to.resolve.to.undefined().then(function(){(0,_must2.default)(a.args).to.eql([['foo',0,b],['bar',1,b],['baz',2,b]])})})}),describe('fromCallback()',function(){it('creates a promise which resolves with value passed to the callback',function(){return(0,_must2.default)((0,_.fromCallback)(function(a){a(null,'foo')})).to.resolve.to.equal('foo')}),it('creates a promise which rejects with reason passed to the callback',function(){return(0,_must2.default)((0,_.fromCallback)(function(a){a('bar')})).to.reject.to.equal('bar')})}),describe('join()',function(){it('calls the callback once promises are resolved',function(){return(0,_.join)(Promise.resolve('foo'),Promise.resolve('bar'),function(a,b){(0,_must2.default)(a).to.equal('foo'),(0,_must2.default)(b).to.equal('bar')})}),it('can takes inputs in an array',function(){return(0,_.join)([Promise.resolve('foo'),Promise.resolve('bar')],function(a,b){(0,_must2.default)(a).to.equal('foo'),(0,_must2.default)(b).to.equal('bar')})}),it('rejects if one promise rejects',function(){return(0,_must2.default)((0,_.join)(Promise.resolve('foo'),Promise.reject('bar'),function(a,b){(0,_must2.default)(a).to.equal('foo'),(0,_must2.default)(b).to.equal('bar')})).to.reject.to.equal('bar')})}),describe('lastly()',function(){it('calls a callback on resolution',function(){var _context10,a={},b=_sinon2.default.spy();return(0,_must2.default)((_context10=Promise.resolve(a),_.lastly).call(_context10,b)).to.resolve.to.equal(a).then(function(){(0,_must2.default)(b.callCount).to.equal(1)})}),it('calls a callback on rejection',function(){var _context11,a={},b=_sinon2.default.spy();return(0,_must2.default)((_context11=Promise.reject(a),_.lastly).call(_context11,b)).to.reject.to.equal(a).then(function(){(0,_must2.default)(b.callCount).to.equal(1)})})}),describe('promisifyAll()',function(){it('returns a new object',function(){var a={},b=(0,_.promisifyAll)(a);(0,_must2.default)(b).to.be.an.object(),(0,_must2.default)(b).to.not.equal(a)}),it('creates promisified version of all functions bound to the original object',function(){var a={foo:function foo(c){c(null,this)}},b=(0,_.promisifyAll)(a);return(0,_must2.default)(b.foo()).to.resolve.to.equal(a)}),it('ignores functions ending with Sync or Async',function(){var a={fooAsync:function fooAsync(){},fooSync:function fooSync(){}},b=_.promisifyAll.call(a);(0,_must2.default)(b).to.not.have.property('foo'),(0,_must2.default)(b).to.not.have.property('fooASync'),(0,_must2.default)(b).to.not.have.property('fooSync')})}),describe('settle()',function(){it('works with arrays',function(){var _context12;return(_context12=[Promise.resolve(42),Math.PI,Promise.reject('fatality')],_.settle).call(_context12).then(function(_ref){var _ref2=_slicedToArray(_ref,3),a=_ref2[0],b=_ref2[1],c=_ref2[2];(0,_must2.default)(a.isFulfilled()).to.equal(!0),(0,_must2.default)(b.isFulfilled()).to.equal(!0),(0,_must2.default)(c.isFulfilled()).to.equal(!1),(0,_must2.default)(a.isResolved()).to.equal(!0),(0,_must2.default)(b.isResolved()).to.equal(!0),(0,_must2.default)(c.isResolved()).to.equal(!1),(0,_must2.default)(a.isRejected()).to.equal(!1),(0,_must2.default)(b.isRejected()).to.equal(!1),(0,_must2.default)(c.isRejected()).to.equal(!0),(0,_must2.default)(a.value()).to.equal(42),(0,_must2.default)(b.value()).to.equal(Math.PI),(0,_must2.default)(c.value.bind(c)).to.throw(),(0,_must2.default)(a.reason.bind(a)).to.throw(),(0,_must2.default)(b.reason.bind(b)).to.throw(),(0,_must2.default)(c.reason()).to.equal('fatality')})}),it('works with objects',function(){var _context13;return(_context13={a:Promise.resolve(42),b:Math.PI,c:Promise.reject('fatality')},_.settle).call(_context13).then(function(_ref3){var a=_ref3.a,b=_ref3.b,c=_ref3.c;(0,_must2.default)(a.isFulfilled()).to.equal(!0),(0,_must2.default)(b.isFulfilled()).to.equal(!0),(0,_must2.default)(c.isFulfilled()).to.equal(!1),(0,_must2.default)(a.isResolved()).to.equal(!0),(0,_must2.default)(b.isResolved()).to.equal(!0),(0,_must2.default)(c.isResolved()).to.equal(!1),(0,_must2.default)(a.isRejected()).to.equal(!1),(0,_must2.default)(b.isRejected()).to.equal(!1),(0,_must2.default)(c.isRejected()).to.equal(!0),(0,_must2.default)(a.value()).to.equal(42),(0,_must2.default)(b.value()).to.equal(Math.PI),(0,_must2.default)(c.value.bind(c)).to.throw(),(0,_must2.default)(a.reason.bind(a)).to.throw(),(0,_must2.default)(b.reason.bind(b)).to.throw(),(0,_must2.default)(c.reason()).to.equal('fatality')})})}),describe('tap(cb)',function(){it('call cb with the resolved value',function(){return new Promise(function(a){var _context14;(_context14=Promise.resolve('value'),_.tap).call(_context14,function(b){(0,_must2.default)(b).to.equal('value'),a()})})}),it('does not call cb if the promise is rejected',function(){var _context15;return(0,_must2.default)((_context15=Promise.reject('reason'),_.tap).call(_context15,function(){return Promise.reject('other reason')})).to.reject.to.equal('reason')}),it('forwards the resolved value',function(){var _context16;return(0,_must2.default)((_context16=Promise.resolve('value'),_.tap).call(_context16,function(){return'other value'})).to.resolve.to.equal('value')}),it('rejects if cb rejects',function(){var _context17;return(0,_must2.default)((_context17=Promise.resolve('value'),_.tap).call(_context17,function(){return Promise.reject('reason')})).to.reject.to.equal('reason')})}),describe('tap(null, cb)',function(){it('call cb with the rejected reason',function(){return new Promise(function(a){var _context18;(_context18=Promise.reject('reason'),_.tap).call(_context18,null,function(b){(0,_must2.default)(b).to.equal('reason'),a()}).catch(function(){})})}),it('does not call cb if the promise is resolved',function(){var _context19;return(0,_must2.default)((_context19=Promise.resolve('value'),_.tap).call(_context19,null,function(){return Promise.reject('other reason')})).to.resolve.to.equal('value')}),it('forwards the rejected reason',function(){var _context20;return(0,_must2.default)((_context20=Promise.reject('reason'),_.tap).call(_context20,null,function(){return'value'})).to.reject.to.equal('reason')}),it('rejects if cb rejects',function(){var _context21;return(0,_must2.default)((_context21=Promise.reject('reason'),_.tap).call(_context21,null,function(){return Promise.reject('other reason')})).to.reject.to.equal('other reason')})}),describe('timeout()',function(){var a=new Promise(function(){});it('rejects a promise if not settled after a delay',function(){return(0,_must2.default)(_.timeout.call(a,10)).to.reject.to.error(_.TimeoutError)}),it('call the callback if not settled after a delay',function(){return(0,_must2.default)(_.timeout.call(a,10,function(){return'bar'})).to.resolve.to.equal('bar')}),it('forwards the settlement if settled before a delay',function(){var _context22;return Promise.all([(0,_must2.default)((_context22=Promise.resolve('value'),_.timeout).call(_context22,10)).to.resolve.to.equal('value'),(0,_must2.default)((_context22=Promise.reject('reason'),_.timeout).call(_context22,10)).to.reject.to.equal('reason')])}),it('rejects if cb throws synchronously',function(){return(0,_must2.default)(_.timeout.call(a,10,function(){throw'reason'})).to.reject.to.equal('reason')})}),describe('unpromisify()',function(){it('forwards the result',function(a){var b=_.unpromisify.call(function(){return Promise.resolve('foo')});b(function(c,d){(0,_must2.default)(c).to.not.exist(),(0,_must2.default)(d).to.equal('foo'),a()})}),it('forwards the error',function(a){var b=_.unpromisify.call(function(){return Promise.reject('foo')});b(function(c){(0,_must2.default)(c).to.equal('foo'),a()})})});
//# sourceMappingURL=index.spec.js.map
{
"name": "promise-toolbox",
"version": "0.6.0",
"version": "0.7.0",
"license": "ISC",

@@ -5,0 +5,0 @@ "description": "Essential utils for promises",

@@ -34,13 +34,66 @@ # promise-toolbox [![Build Status](https://travis-ci.org/JsCommunity/promise-toolbox.png?branch=master)](https://travis-ci.org/JsCommunity/promise-toolbox)

### Decorators
### Cancellation
#### cancellable
This library provides an implementation of `CancelToken` from the
[cancelable promises specification](https://tc39.github.io/proposal-cancelable-promises/).
A cancel token is an object which can be passed to asynchronous
functions to represent cancellation state.
```js
import { CancelToken } from 'promise-toolbox'
```
#### Creation
A cancel token is created by the initiator of the async work and its
cancellation state may be requested at any time.
```js
// Create a token which requests cancellation when a button is clicked.
const token = new CancelToken(cancel => {
$('#some-button').on('click', () => cancel('button clicked'))
})
```
#### Consumption
The receiver of the token (the function doing the async work) can:
1. synchronously check whether cancellation has been requested
2. synchronously throw if cancellation has been requested
3. register a callback that will be executed if cancellation is requested
4. pass the token to subtasks
```js
// 1.
if (token.requested) {
console.log('cancellation has been requested')
}
// 2.
token.throwIfRequested()
// 3.
token.promise.then(() => {
console.log('cancellation has been requested')
})
// 4.
subtask(token)
```
#### @cancellable decorator
> Make your async functions cancellable.
If the first argument passed to the cancellable function is not a
cancel token, a new one is created and injected and the returned
promise will have a `cancel()` method.
```js
import { cancellable } from 'promise-toolbox'
import { cancellable, CancelToken } from 'promise-toolbox'
const asyncFunction = cancellable(async function (cancellation, a, b) {
cancellation.catch(() => {
const asyncFunction = cancellable(async ($cancelToken, a, b) => {
$cancelToken.promise.then(() => {
// do stuff regarding the cancellation request.

@@ -52,4 +105,10 @@ })

const promise = asyncFunction('foo', 'bar')
promise.cancel()
// Either a cancel token is passed:
const source = CancelToken.source()
const promise1 = asyncFunction(source.token, 'foo', 'bar')
source.cancel('reason')
// Or the returned promise will have a cancel() method:
const promise2 = asyncFunction('foo', 'bar')
promise2.cancel('reason')
```

@@ -63,8 +122,4 @@

@cancellable
async asyncMethod (cancellation, a, b) {
cancellation.catch(() => {
// do stuff regarding the cancellation request.
})
// do other stuff.
async asyncMethod ($cancelToken, a, b) {
// ...
}

@@ -71,0 +126,0 @@ }

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc