Advertisement
Guest User

Untitled

a guest
Oct 18th, 2019
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.39 KB | None | 0 0
  1. /**
  2. * Execute a function repeatedly when frame change.
  3. * @param {Function} func
  4. * @param {any} args
  5. * @return {stop} : Function to stop the loop
  6. */
  7. function frameLoop(func, ...args) {
  8. let loop = true;
  9.  
  10. (async function execute() {
  11. await nextFrame();
  12.  
  13. func(...args);
  14.  
  15. if (loop) execute();
  16. })();
  17.  
  18. return stop;
  19.  
  20. function stop() {
  21. loop = false;
  22. }
  23. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement