Answer the question
In order to leave comments, you need to log in
Are the two codes the same?
There is a code
like thispromise.then(value=>value).then(value=> ...)
promise.then(value=>Promise.resolve(value)).then(value=> ...)
Answer the question
In order to leave comments, you need to log in
If promise
resolved with a non-promise value value
, then promise.then(value => value)
and are promise.then(value => Promise.resolve(value))
equivalent to promises in the above chain.
The statuses of these promises are the same.
If the promise resolves with the promise value value, then promise.then(value => value)
both promise.then(value => Promise.resolve(value))
are equivalent: they will return a promise that resolves with the value that resolves to value
.
PS To be honest, I don't know how to make a promise resolve to a value that is itself a promise. A cursory lurk and SO suggest that this is not possible, unless we wrap the promise returned during resolution in an object ( link )
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question