Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.Sign up
Implement _enqueueImmediate #9001
In an upcoming commit the library uses "_enqueueImmediate" with the following properties:
Callbacks register through this function are always executed in order and are guaranteed to run before other asynchronous events (like [Timer] events, or DOM events).
Note: currently it would be ok to only allow one callback at a time. If you chose to implement the function with this behavior please let me (floitsch) know and I will update the documentation to make sure it won't be used otherwise.
I don't think this bug is stale. It's still referred to from our public docs (https://www.dartlang.org/articles/event-loop/), and the incorrect behavior described there still exists under the VM (see https://www.dartlang.org/articles/event-loop/#question-2).
Here's a shorter repro:
This code should print:
since the microtask should execute before the event to print "Future 2" is popped off the event loop. This works correctly in Dart2js, but the VM prints:
Added Triaged label.
This is still AssumedStale.
The problem described in comment #5 is due to how the Future(computation) is implemented. Futures scheduled within the same event will ALL be executed in the same run of the timer before returning to the event loop. Thus Future 1 and Future 2 will execute before any micro tasks fire. If you believe this is an error, then please file a bug against the Future implementation.
So two (or more) timers that are scheduled for the same time (zero-duration timers scheduled right after each other generally are) then they are executed as one top-level event, not two, and with no microtasks executed between them.
That does sound wrong. The reason for using a timer instead of a microtask is to allow top-level events between them (including browser redraw events).
This is not a Future issue, it's a Timer issue. The same behavior is exhibited by:
I don't mind the merging of events that much (but it is surprising if it prevents redraw), but microtasks should still be run between the timer events.
That's not this bug, though. This bug was for making microtasks possible at all, which has been done.