Skip to content

Instantly share code, notes, and snippets.

@electerious
Created July 27, 2017 12:24
Show Gist options
  • Save electerious/e4fef1a1355bdf3505cdc24da1701486 to your computer and use it in GitHub Desktop.
Save electerious/e4fef1a1355bdf3505cdc24da1701486 to your computer and use it in GitHub Desktop.
Loop an async function with a delay
const loop = (fn, delay) => {
const next = () => setTimeout(
() => loop(fn, delay),
delay
)
fn(next)
}
@electerious
Copy link
Author

Example:

const fn = (next) => {
	console.log('looping')
	next()
}

loop(fn, 1000)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment