Skip to content

Commit 8c3343f

Browse files
Expand the readme's motivation section with use cases (#30)
1 parent 9d3868d commit 8c3343f

File tree

1 file changed

+40
-1
lines changed

1 file changed

+40
-1
lines changed

README.md

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,46 @@ Champions:
1010

1111
The goal of the proposal is to provide a mechanism to ergonomically track async
1212
contexts in JavaScript. Put another way, it allows propagating a value through
13-
a callstack regardless of any async execution.
13+
a callstack regardless of any async execution, without needing to explicitly
14+
pass the value from task to task.
15+
16+
Use cases for this include:
17+
18+
- Annotating logs with information related to an asynchronous callstack.
19+
20+
- Collecting performance information across logical asynchronous threads of
21+
control. This includes timing measurements, as well as OpenTelemetry. For
22+
example, OpenTelemetry's
23+
[`ZoneContextManager`](https://open-telemetry.github.io/opentelemetry-js/classes/_opentelemetry_context_zone_peer_dep.ZoneContextManager.html)
24+
is only able to achieve this by using zone.js (see the prior art section).
25+
26+
- There are a number of use cases for browsers to track the attribution of tasks
27+
in the event loop, even though an asynchronous callstack. They include:
28+
29+
- Optimizing the loading of critical resources in web pages requires tracking
30+
whether a task is transitively depended on by a critical resource.
31+
32+
- Tracking long tasks effectively with the
33+
[Long Tasks API](https://w3c.github.io/longtasks) requires being able to
34+
tell where a task was spawned from.
35+
36+
- [Measuring the performance of SPA soft navigations](https://developer.chrome.com/blog/soft-navigations-experiment/)
37+
requires being able to tell which task initiated a particular soft
38+
navigation.
39+
40+
- Transitive task prioritization: The
41+
[Prioritized Task Scheduling API](https://wicg.github.io/scheduling-apis/)
42+
allows setting the priority a task should have in the event loop, but that
43+
does not currently extend to task spawned from that one.
44+
45+
- Limiting access to certain APIs transitively, such as sensitive or
46+
high-entropy APIs from less-trusted scripts and any tasks they might spawn.
47+
48+
Hosts are expected to use the infrastructure in this proposal to allow tracking
49+
not only asynchronous callstacks, but other ways to schedule jobs on the event
50+
loop (such as `setTimeout`) to maximize the value of these use cases.
51+
52+
## A use case in depth: logging
1453

1554
It's easiest to explain this in terms of setting and reading a global variable
1655
in sync execution. Imagine we're a library which provides a simple `log` and

0 commit comments

Comments
 (0)