The same two codes?

There is here such code
promise.then(value=>value).then(value=> ...)
and so
promise.then(value=>Promise.resolve(value)).then(value=> ...)

Do I understand correctly that if the handler for the promis we return just the value here (value=> value), it returns a promise which is automatically able resolve? what does the function Promise.resolve() - returns an already resolved promise.
June 8th 19 at 17:17
1 answer
June 8th 19 at 17:19
Solution
If promise resolves with non-prominin value value, the promise.then(value => value) and promise.then(value => Promise.resolve(value)) is equivalent to the promise in the above chain.
The status of these promises are the same.

If promise resolves with prominin value, we promise.then(value => value) and promise.then(value => Promise.resolve(value)) are equivalent: they return a promise that resolves with the value from the permitted value.

P. S. I honestly don't know how to make a promis that would have resolved with a value, which is itself a promise. Fluent lurkage and SO prompt that it is impossible, unless we wrap the returned during resolution of the promise object (referring)
I've meant the fact that the promis promise where it will resolve(variable).
You mean of what variable? Promise or let the string?
I wanted to ask if we returned here so value=>value, then we would automatically return already resolved promise? So? In the second code I made is clearly. It is returned already resolved promise. - karley.Abshi commented on June 8th 19 at 17:22
Let the example below along the way to resolve the terminological mix-up.
For example,
function ret(x) {
 return new Promise(resolve => {
 console.log('timer for' + x);
 setTimeout(() => resolve(x()), 1000)
});
}

const promise = ret(() => 42);

promise is pending with the state for second, then resolves with the value 42.
const promise = ret(() => 42);
const p = promise.then(value => value);

p behaves completely equivalent to the promise. They are both first in pending, then resolved with the value 42.
const promise = ret(() => 42);
const p = promise.then(value => Promise.resolve(value));

Same thing here.

upd. offer the example of promis to understand. I might misunderstand the point of asking, so I give the soil to expand and clarify the issue. - Ida_Goyet commented on June 8th 19 at 17:25
turns out in both cases, the variable p will be allowed promis, which in itself will keep the value?

In this case, the return to R promis in which to store value?
const promise = ret(() => 42);
const p = promise.then(value => value);


In this case, the return to R promis in which to store Promise.resolve(value)?
const promise = ret(() => 42);
const p = promise.then(value => Promise.resolve(value));
- karley.Abshi commented on June 8th 19 at 17:28
again , I did not understand.
Just in case I repeat.
it turns out in both cases, the variable p will be allowed promis, which in itself will keep the value?
No p at the time of determination has promise as pending and will be resolved. View in DevTools, for example.
return to R promis
to decipher this phrase.
Colback the argument (then) returns in the first case, the value (42) as is, and the second promise resolved with the value 42.
This colback is called a second after the initialized variables promise and p.
The method then returns a promise, who is the first second is pending, then resolved with the value 42. - Ida_Goyet commented on June 8th 19 at 17:31
,
return to R promis

I meant that then returns a promise, then also call the next .then

Here I made the snapshot.
take.ms/lYkw8
Thanks for the replies. - karley.Abshi commented on June 8th 19 at 17:34
Put in a setTimeout delay of 20+ seconds and then repeat.
In the screenshot, the status is resolved only because you were probably typing commands longer than a second.
About the fact that the processors are different, you're right. But then behaved the same way. - Ida_Goyet commented on June 8th 19 at 17:37

Find more questions by tags JavaScript