coopernurse / node-pool

Generic resource pooling for node.js
2.38k stars 259 forks source link

make doWhileAsync really async and avoid stack overflow #149

Closed dchekmarev closed 8 years ago

dchekmarev commented 8 years ago

Sample to fail the original code with RangeError: Maximum call stack size exceeded:

global._doWhileAsyncCount=0;
doWhileAsync(
  () => global._doWhileAsyncCount < 1000000,
  (next) => { global._doWhileAsyncCount++; next(); },
  () => {console.log("done");
});

Plus this allows doWhileAsync to be really async and to return execution before callbackFn call (in case when we have at least 1 additional iteration).

dchekmarev commented 8 years ago

oups, should check/fix tests and stuff around first :)

sandfox commented 8 years ago

@dchekmarev there is a V3 branch where all this stuff is completely fixed (via promises stuff). I'm still fixing up docs and the tests could do with improvement. I haven't yet published it as an ALPHA (or next release) on npm, but if you want to use it I'm more than happy to do a quick tidy up of my commits and publish it (as ALPHA/BETA)