Guest User

Untitled

a guest
Jun 20th, 2018
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.52 KB | None | 0 0
  1. // created by crodas -- Public domain
  2.  
  3. // private, number of running processes
  4. var running = 0;
  5.  
  6. // sort of try time
  7. exports.time = 10;
  8. // limit, max 5 running processes
  9. exports.limit = 5;
  10.  
  11. exports.exec = function(callback) {
  12. if (typeof callback != "function") {
  13. throw ("callback is not a valid function");
  14. }
  15. var i = setInterval(function() {
  16. if (running < exports.limit) {
  17. running++;
  18. callback();
  19. running--;
  20. clearInterval(i);
  21. }
  22. }, exports.time);
  23. };
Add Comment
Please, Sign In to add comment