S
S
sergmit2019-05-30 10:06:59
JavaScript
sergmit, 2019-05-30 10:06:59

How to determine when the recursion ends?

How to determine the end of execution of such a recursive function:

function rec(text) {
    asynFunc(text).then(data => {
        if (data.length > 10) {
            rec(data);
        }
    })
}

Answer the question

In order to leave comments, you need to log in

2 answer(s)
L
Lynn "Coffee Man", 2019-05-30
@sergmit

function rec(text) {
    return asynFunc(text).then(data => {
        if (data.length > 10) {
            return rec(data);
        }
    })
}

rec(text).then(() => console.log("Закончилось"));

K
kova1ev, 2019-05-30
@kova1ev

It depends on asynFunc()
As soon as the promise in it is fulfilled with a result that does not satisfy the condition, it will end.
If asynFunc always returns the same value with the same argument, it will never end.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question