Advertisement
Guest User

Untitled

a guest
Nov 22nd, 2016
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.32 KB | None | 0 0
  1. function runScript(times, interval, block) {
  2. function sleep (time) {
  3. return new Promise((resolve) => setTimeout(resolve, time));
  4. }
  5.  
  6. i = 1;
  7. thenBlock = (() => {
  8. block();
  9. if(++i > times) return;
  10. sleep(interval).then(thenBlock);
  11. });
  12. thenBlock()
  13. };
  14.  
  15. runScript(5, 100, function(){ console.log('test log') })
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement