Advertisement
Guest User

Node.js async.whilst

a guest
Jan 5th, 2017
269
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. var async = require('async');
  2.  
  3. var before = Date.now();
  4.  
  5. async.whilst(always, gameloop, stop);
  6.  
  7. function always() { return true; }
  8.  
  9. function gameloop(next)
  10. {
  11.     var after = Date.now();
  12.     var dt = after - before;
  13.     if (dt >= 500)
  14.     {
  15.         console.log("yipee!");
  16.         before = after;
  17.     }
  18.     process.nextTick(next);
  19. }
  20.  
  21. function stop()
  22. {
  23.     console.log("loop has stopped for some reason when it shouldn't")
  24. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement