site-www icon indicating copy to clipboard operation
site-www copied to clipboard

Document microtasks

Open kwalrath opened this issue 5 years ago • 6 comments

With the disappearance of the out-of-date article "The Event Loop and Dart", we no longer have any doc on dart.dev for microtasks. Microtasks are mentioned in /articles/archive/zones, but that article, too, is out of date.

The scheduleMicrotask API docs point to the old event loop article (/articles/event-loop, which is forwarded to the Medium article made from Andrew's event loop video). It'd be good to have actual coverage of the event loop and microtasks somewhere on dart.dev, and to redirect /articles/event-loop to that coverage.

kwalrath avatar Nov 27 '19 23:11 kwalrath

Interim fix: add link from Andrew's event loop article to an archive URL like https://web.archive.org/web/20170704074724/https://webdev.dartlang.org/articles/performance/event-loop.

DONE

kwalrath avatar Jan 23 '20 21:01 kwalrath

I've just discovered an internal resource that seems helpful: go/dart-await. It refers to this DartPad and this article.

kwalrath avatar Jan 27 '20 17:01 kwalrath

There's a new concurrency page, but it doesn't cover microtasks: https://dart.dev/guides/language/concurrency

kwalrath avatar Feb 01 '22 22:02 kwalrath

Hi @kwalrath , searching "dart event loop" on Google, the first result is https://dart.cn/articles/archive/event-loop, which is the same as the archive URL you mentioned above.

While waiting for someone to create an updated doc, I'm curious if you know whether these points in the old doc are still true:

Fun facts about Future:

1. The function that you pass into Future’s then() method executes immediately when the Future completes. (The function isn’t enqueued, it’s just called.)
2. If a Future is already complete before then() is invoked on it, then a task is added to the microtask queue, and that task executes the function passed into then().
3. The Future() and Future.delayed() constructors don’t complete immediately; they add an item to the event queue.
4. The Future.value() constructor completes in a microtask, similar to #2.
5. The Future.sync() constructor executes its function argument immediately and (unless that function returns a Future) completes in a microtask, similar to #2.

terryl1900 avatar May 25 '22 16:05 terryl1900

@lrhn Would you be able to provide some input on @terryl1900's questions? We could also use your responses as guidelines when creating any new documentation around this. Thanks :)

parlough avatar May 26 '22 18:05 parlough

I believe the mentioned bugs in the article have been fixed - when running the examples they now show in the expected order (which is a bit different from what was 'then' true) - right now we are missing a good writeup on the event loop, it's also difficult to find the implementation in C, which is something I was trying to get to (the JS event loop is quite easy to find)

dkbast avatar Jan 25 '24 13:01 dkbast