-
Notifications
You must be signed in to change notification settings - Fork 0
/
tsnafp.min.js
6 lines (6 loc) · 1.46 KB
/
tsnafp.min.js
1
2
3
4
5
6
// async.js v1.0.2
//
// Copyright © 2014 Fernando Faria <[email protected]> <github.com/myfingersarebroken>
// Dual licensed under GPLv2 & MIT
;function _interval(userData,func,wait,times){var state={maxCalls:times||Number.POSITIVE_INFINITY,actualCall:0,data:[],lastComputedData:null,error:[],lastComputedError:null,lastCall:false,proceed:function(){},then:function(){},clear:function(){},stopOnError:true,isRunning:true,userData:userData};var interv=(function(w,t){function i(){if(t==0){state.isRunning=false;}if(t==1){state.lastCall=true;}if(t-->0){try{i.state.data[state.actualCall]=func.call(i,state);i.state.lastComputedData=i.state.data[state.actualCall];state.actualCall+=1;}catch(e){if(state.stopOnError){t=0;}i.state.error[state.actualCall]=e;i.state.lastComputedError=i.state.error[state.actualCall];try{i.state.data[state.actualCall]=func.call(i,state);i.state.lastComputedData=i.state.data[state.actualCall];}catch(er){if(!state.stopOnError){state.actualCall+=1;}}}setTimeout(interv,w);}}state.clear=function(){if(!state.isRunning){return null;}t=0;state.isRunning=false;return null;};state.proceed=function(){if(state.isRunning){return null;}t=state.maxCalls-state.actualCall;state.isRunning=true;setTimeout(interv,w);return null;};i.state=state;i.clear=state.clear;i.proceed=state.proceed;return i;})(wait,times||Number.POSITIVE_INFINITY);setTimeout(interv,wait);return interv;}
;function _async(userData,func,wait,times){return _interval(userData,func,wait,times);}