Skip to content
Advertisement

Delay before recursive function call

I’m trying to set a delay before every recursive function call. Currently, it’s returning undefined. The problem might be the scope of the recursive call (inside settimeout and then). I tried it like this:

JavaScript

And this:

JavaScript

Any help is appreciated!

Advertisement

Answer

You need to turn checkIfListElementIsRendered to async/await syntax, and await the delay and checkIfListElementIsRendered methods, Also instead return true turn it to promise to be always return a promise.

When you call checkIfListElementIsRendered method outside, you need to resolve it with await or then callback.

JavaScript
User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement