Alex Trupin
Alex Trupin

Reputation: 111

How to wait for a function finish in an infinite loop?

I have a function that must finish its job to restart again, and that for infinite time in nodejs.

So I just want to create an infinite loop, synchronous, that only execute on function.

I tried a lot of things, but all I tested didn't worked.

In other synchronous languages, this function will looks like :

while(42) {
myfunc();
}

And this function returns a promise.

Can you help me please ?

Upvotes: 1

Views: 838

Answers (1)

Yury Tarabanko
Yury Tarabanko

Reputation: 45121

"And this function returns a promise."

myfunc().then(myfunc)

UPD. Demo.

function run() {
    myfunc().then(run)
}

run()

Upvotes: 3

Related Questions