I'm playing around with Promises, but I cannot figure out how to get back the value as a result of it work? So, in promise .then
stage it gives me the right result, but outside it's showed as Promise <pending>
. What I forgot?
Thank you.
P.S. Please, do not block my question, I saw tens of similar this one, but it does not help me
const computeResult = () => {
return 2
}
const randomizer = () => {
const delay = 1000
return new Promise(r => setTimeout(r, delay)).then(() => computeResult());
}
const randomID = randomizer()
.then(res => {
console.log(res, 'res') // return what expected - '2'
return res
})
.catch(e => console.log(e.message))
console.log(randomID, 'randomID') // return always Promise <pending>