Skip to content

Instantly share code, notes, and snippets.

@okabe-yuya
Created January 3, 2021 06:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save okabe-yuya/fbb05d1aa08feac64c8179173ca205fd to your computer and use it in GitHub Desktop.
Save okabe-yuya/fbb05d1aa08feac64c8179173ca205fd to your computer and use it in GitHub Desktop.
const interval = async (msFunc, callback, continueCond) => {
const _interval = async () => {
const sleepTime = msFunc();
console.log("sleepTime: ", sleepTime);
await new Promise(resolve => {
setTimeout(resolve, sleepTime);
});
if (continueCond()) {
callback();
await _interval();
}
};
await _interval();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment