UNPKG

runner-js

Version:

Better Async Handler To Simplify Your Async Flow Process And Code Testing

8 lines 4.37 kB
/*! * Copyright (c) Naufal Rabbani (http://github.com/BosNaufal) * Licensed Under MIT (http://opensource.org/licenses/MIT) * * Runner JS @ Version 0.0.3 * */ !function(e,n){"object"==typeof exports&&"object"==typeof module?module.exports=n():"function"==typeof define&&define.amd?define([],n):"object"==typeof exports?exports.Runner=n():e.Runner=n()}(this,function(){return function(e){function n(r){if(t[r])return t[r].exports;var u=t[r]={exports:{},id:r,loaded:!1};return e[r].call(u.exports,u,u.exports,n),u.loaded=!0,u.exports}var t={};return n.m=e,n.c=t,n.p="../dist/",n(0)}([function(e,n,t){"use strict";function r(e){return e&&e.__esModule?e:{default:e}}Object.defineProperty(n,"__esModule",{value:!0}),n.race=n.concurrent=n.delay=n.call=n.Runner=void 0;var u=t(2),o=t(1),c=r(o);n.Runner=c.default,n.call=u.call,n.delay=u.delay,n.concurrent=u.concurrent,n.race=u.race,n.default=c.default},function(e,n){"use strict";function t(e){return"function"==typeof e}function r(e){return void 0!==e.then}function u(e){return"function"==typeof e.prototype.next}function o(e){return"object"===("undefined"==typeof e?"undefined":m(e))&&!e.length}function c(e){return"object"===("undefined"==typeof e?"undefined":m(e))&&e.length}function i(e){return 0!==Object.keys(e).length}function f(e,n,t){var r=t.runNext,u=t.currentRunningFunction;return e.then(function(e){return n?n(e):r(u,e)})}function a(e,n,o){var c=o.Runner,i=o.runNext,a=o.currentRunningFunction,l=o.store,s=(e.method,e.func),p=e.args;if(t(s)){var d=s.apply(s,p);return r(d)?f(d,n,o):u(s)?c(s,l).then(function(e){return n?n(e):i(a,e)}):n?n(d):i(a,d)}}function l(e){var n=e.allResponses,t=e.index,r=e.res,u=e.key,o=e.wrapper;return"concurrent"===o.type?(n.push(r),n):"race"===o.type?i(n)?n:(n[u]=r,n):(u?n[u]=r:n.splice(t,0,r),n)}function s(e){var n=e[0].key,t=n?{}:[],r=function(e){return n?Object.keys(t).length===Object.keys(e).length:t.length===e.length};return{allResponses:t,isDone:r}}function p(e,n){for(var t=n.runNext,r=n.currentRunningFunction,u=s(e),o=u.allResponses,c=u.isDone,f="race"===e[0].type,p=function(){var u=e[d],s=d,p=u.key||!1;a(u,function(n){if(o=l({allResponses:o,index:s,key:p,res:n,wrapper:u}),c(e)||f&&i(o))return t(r,o)},n)},d=0;d<e.length;d++)p()}function d(e,n){return c(e)?e.map(function(e){return h({},e,{type:n})}):o(e)?Object.keys(e).map(function(t){var r=e[t];return h({},r,{type:n,key:t})}):void 0}function y(e){var n=o(e)&&!e.method;if(n)return d(e);if(!e.method)return e;var t=e.func;return"CONCURRENT"===e.method?d(t,"concurrent"):"RACE"===e.method?d(t,"race"):void 0}function v(e){var n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return new Promise(function(r,u){function i(e){var u=arguments.length>1&&void 0!==arguments[1]?arguments[1]:null,f=e.next(u),l=f.value,s=f.done,d={Runner:v,runNext:i,currentRunningFunction:e,store:n};if(!s){if(!l)throw new Error('[Redux Runner]: Please wrap the function next to yield statement inside the effects e.g. "call" or "put"');var h=t(l.func);if(h)return a(l,!1,d);if(o(l)||c(l)){var m=y(l);return p(m,d)}return i(e,l)}r(f.value)}var f="function"==typeof e?e(n):e;return i(f)})}Object.defineProperty(n,"__esModule",{value:!0});var h=Object.assign||function(e){for(var n=1;n<arguments.length;n++){var t=arguments[n];for(var r in t)Object.prototype.hasOwnProperty.call(t,r)&&(e[r]=t[r])}return e},m="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e};n.objectHasBeenFilled=i,n.doPromise=f,n.runGenerator=a,n.makeAResponse=l,n.getParallelParameter=s,n.runParallel=p,n.setWrapperType=d,n.destructureWrapper=y,n.default=v},function(e,n){"use strict";function t(e){var n=e[0];if(e=Array.prototype.slice.call(e,1,e.length),"function"!=typeof n)throw new Error("[Genfunction]: First Argument Should Be a Function");return{func:n,args:e}}function r(e,n,t){return{wrapped:!0,method:e,func:n,args:t}}function u(){var e=t(arguments),n=e.func,u=e.args;return r("CALL",n,u)}function o(e){return r("CONCURRENT",e)}function c(e){return r("RACE",e)}function i(e){return new Promise(function(n,t){setTimeout(function(){n(!0)},e)})}Object.defineProperty(n,"__esModule",{value:!0}),n.call=u,n.concurrent=o,n.race=c,n.delay=i,n.default={call:u,concurrent:o,race:c,delay:i}}])});