You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
constcounter=metasync.count(5).timeout(2000).done(err=>{/* timed out or done */});counter(4);counter(-2);counter(10);// now value = 12 but > 5 and we will call 'done'
As I understood, I should make method .count(a) as option and then make counter(b) anywhere I want. If b was less than a before async fn had finished it execution, done would be done with error.
Correct me if I am not right, and I also can take this task.
What can you say about this implementation as example? I am not sure about callback done. What args should I pass to this fn and what way?
consttimeout=(timeout,count,fn,callback)=>{letfinished=false;letcurcount=0;consttimer=setTimeout(()=>{finished=true;callback(newError(FN_TIMEOUT));},timeout);constsum=arg=>{curcount+=arg;if(count>curcount)returnsum;finished=true;clearTimeout(timer);callback();// donereturnnull;};fn((...args)=>{if(!finished){clearTimeout(timer);finished=true;callback(...args);}});returnsum;};constdata=metasync.timeout(10000,5,callback=>{setTimeout(()=>{callback(null,'someVal',1,2,3,4);},1000);},(err,res, ...args)=>{if(err)console.error(err);else{console.log(res);console.log(args);}});data(1);data(1);data(6);// there callback will be called but without args// or I can make something like thisfunctionCount(count){this.count=count;this.curcount=0;this.cb=null;this.to=null;}Count.prototype.timeout=function(to){this.to=to;returnthis;};Count.prototype.done=function(fn){this.cb=fn;constsum=arg=>{this.curcount+=arg;if(this.count>this.curcount)returnsum;this.cb(/*...args*/);returnnull;};returnsum;};constcount=arg=>newCount(arg);constdata=count(10).timeout(2000).done(err=>{if(err){/*...*/}else{/*...*/}});data(4);data(-10);data(500);// callback here
@nechaido please assign to somebody
The text was updated successfully, but these errors were encountered: