Eternalcode Eternalcode - 1 year ago 93
Dart Question

Can anyone explain this behavior?

I accidentally came across this behavior while playing around the async behavior.

Can anyone explain to me why the setTimeout with 0 seconds is not executing the print statement immediately?

Answer Source

setTimeout enqueues the passed function into the event queue and the passed code is executed async.

The sync code is executed to the end and then the next event in the event queue is processed.