I'm confused about resolve
in Promise.
resolve
is invoked before innerResolve
, but why 'inner Promise then execute' is logged before 'Promise then execute' in chrome console.
I think it might be that:
When the state of a promise is PENDING, invoking resolve
just set the state to FULFILLED, and when then
method is invoked the job will be queued into jobQueue.innerPromise.then
is invoked first, so the job is queued first.
Is there a normative explanation to this question?
Here is my code:
console.log("main start")
new Promise(resolve =>{
new Promise(innerResolve =>{
resolve()
console.log("resove is called")
innerResolve()
console.log("innerResolve is called")
}).then(() => {
console.log('inner Promise then execute')
})
}).then(() => {
console.log('Promise then execute');
})
console.log("main end")