Combination of async function + await + setTimeout
Your sleep function does not work because setTimeout does not (yet?) return a promise that could be awaited. You will need to promisify it manually: Btw, to slow down your loop you probably don’t want to use a sleep function that takes a callback and defers it like this. I recommend: which lets the computation of parents take at least 5 seconds.