Skip to content

Commit 95846e7

Browse files
committed
docs: work on causality.mdx
1 parent 9038de1 commit 95846e7

File tree

1 file changed

+16
-18
lines changed

1 file changed

+16
-18
lines changed

packages/docs/src/content/docs/tech/causality.mdx

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,11 @@ Other http frameworks provide a single thread of execution, and a global
4444
environment object which is used to configure each request and response in turn.
4545

4646
With Pardon, we offer the same ergonomics of a "global object", but the behavior
47-
is stable across promises: only awaited "assignments" to the "global object" are
48-
seen.
47+
is independent of the execution order: since only _awaited_ assignments to the
48+
global object count.
4949

5050
The base of this is a tracking system that understands
51-
"what happened" to reach a certain point.
51+
_what happened_ to reach a certain point, by way of a series of tracked values.
5252

5353
In a single threaded usage, `track(value)` looks like it pushes a value
5454
onto a list and `awaited()` returns that list.
@@ -96,14 +96,16 @@ awaited(); // ['f', 'g']
9696
```
9797

9898
Notice that `awaited()` above can return any combination of `'f'` and/or `'g'`
99-
in any order: depending on the order they were awaited,... rather than
100-
the order the `track` calls were executed.
99+
in different orders: depending purely on the order they were awaited,
100+
rather than the order the `track` calls were actually run!
101101

102-
This might feel a bit weird, but it is _stable_, as the `awaited()` result is
103-
based on the shape of the code, rather than the unstable order of execution.
102+
This might feel a bit weird at first, but it is _stable_, as the composition/order of the `awaited()`
103+
values will be based only on the (stable) lexical shape of the code, rather than the
104+
unstable order of execution.
104105

105-
We use this to track assignments to a global environment value as
106-
well as tracking the requests that comprise a particular test.
106+
In tests, we use this to track assignments to a global environment value.
107+
We also track dependent requests that might be executed via script helpers to
108+
surface dependent requests in `favor`.
107109

108110
## How this Tracks
109111

@@ -158,18 +160,14 @@ executes synchronously as well, while
158160

159161
Like all non-trivial abstractions, this one leaks: Memory.
160162

161-
Obviously, the values in the `awaited()` list are "referenced" by the
162-
promises that carry them, but that reference is implemented by a graph
163-
of the execution of all the promises.
164-
165-
The graph _is_ garbage-collected along with promises, as much as possible,
163+
The awaited values _are_ garbage-collected along with promises, as much as possible,
166164
but we have two helpers to cut the graph for correctness and
167165
better garbage collection, respectively.
168166

169-
- `shared(() => { ... })` cuts the graph into the execution of `...`.
170-
- `disconnected(() => { ... })` cuts the graph leaving the execution `...`.
167+
- `shared(() => { ... })` drops awaited values going into the execution of `...`.
168+
- `disconnected(() => { ... })` drops awaited values leaving the execution of `...`.
171169

172-
Both of these methods immediately execute their function and
170+
Both of these methods asynchronosuly start executing their function and
173171
return a promise for its result.
174172

175173
### Shared Execution
@@ -186,7 +184,7 @@ function getAuthToken() {
186184
in this case the `authTokenPromise` will inherit the tracked values
187185
leading to the first call of `fetchAuthToken()` only. This introduces
188186
a race condition as the tracked results of `getAuthToken()` would
189-
depend on who called it first. Additioanlly the `fetchAuthToken()` function
187+
depend on who called it first. Additionally the `fetchAuthToken()` function
190188
would have access to the `awaited()` values of its first caller.
191189
192190
To fix this, we use `shared` to disconnect the execution graph leading into the call.

0 commit comments

Comments
 (0)