JSFiddle - React, Tailwind, and code Playground
JavaScript
function asyncFun (x) {
return new Promise(res => {
setTimeout(() => res(x), 2000)
})
}
function logAndIncrememntIfNeeded(x) {
return asyncFun(x)
.then(res => {
console.log(res)
return res
})
.then(res => {
console.log(res + ', but is it?')
if (res > 200) return 'OK'
else return logAndIncrememntIfNeeded(res + 100)
})
.then(res => {
console.log(res)
})
}
logAndIncrememntIfNeeded(5)