#asynccontext — Public Fediverse posts
Live and recent posts from across the Fediverse tagged #asynccontext, aggregated by home.social.
-
I was having a conversation about #AbortSignal and the difficulties with managing it / passing through properly and it made me realize that #AsyncContext could totally solve this problem?
What if we had a standard `AsyncContext.signal` built-in and then anyone can check and listen to that to know when they are aborted. Even other standard functions could check this to handle abort behavior automatically.
Imagine if `fetch` automatically aborted based on this signal:
```typescript
async function parent(): Promise<void> {
await child();
}async function child(): Promise<void> {
const res1 = await fetch('/one'); // Inherits `AsyncContext.signal`.
const res2 = await fetch('/two'); // Inherits `AsyncContext.signal`.
// ...
}// Run `parent()` and timeout after 1sec.
await AsyncContext.signal.run(AbortSignal.timeout(1_000), () => parent());
```That seems pretty useful. I filed https://github.com/tc39/proposal-async-context/issues/103 to discuss the idea further.