Is it possible for custom code to be executed between resolving a promise and the promise is pending return?
function a () { return new Promise(resolve => { setTimeout(() => { // Between here... resolve() }, 1000)) } } async function b () { await a() // ...and here ? }
Does the specification indicate that Promise callbacks are called immediately? I wonder if the event can be processed by the virtual machine between two points, which can cause side effects.
No, it does not provide an immediate call. The spectrum goes through several steps in resolving a promise, one of which is:
EnqueueJob ( "PromiseJobs", PromiseResolveThenableJob, ", , thenAction" )
, . , EnqueueJob, :
queueName.
, .
. b()
b()
function b () { return a().then(() => { // Do something }); }
, then, eventloop , a. , , Promise ( , eventloop). (, ) , , .
then
a
Source: https://habr.com/ru/post/1682201/More articles:Powershell Music File Metadata Access - c #CallBack iOS not working - objective-c1 row exception from VBA Copy Range - vbaнайти ближайшую точку (геометрия) - javaWhat does value mean in relation to python objects? - pythonhow to use ng-repeat loop by count in angularJS - angularjsHow to remove default button class dataTables buttons? - javascriptDjango SMTP error: authentication error: authentication error - python[SonarLint]: make this anonymous inner class a lambda - lambdaNumber in java, how does it work without a subclass? - javaAll Articles