https://github.com/benjamingr/cancellation-propagation-example
Please don't use this ^^ I have no idea if this idea is good.
https://github.com/benjamingr/cancellation-propagation-example
Last synced: 3 months ago
JSON representation
Please don't use this ^^ I have no idea if this idea is good.
- Host: GitHub
- URL: https://github.com/benjamingr/cancellation-propagation-example
- Owner: benjamingr
- Created: 2021-01-18T12:17:17.000Z (over 4 years ago)
- Default Branch: main
- Last Pushed: 2021-01-18T13:01:14.000Z (over 4 years ago)
- Last Synced: 2025-02-13T16:47:40.939Z (5 months ago)
- Language: JavaScript
- Size: 38.1 KB
- Stars: 1
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
### Cancellation propagation attempt
This code does automatic signal propagation using `AsyncLocalStorage`, it's pretty short and its purpose is to see if this API is useful, useless or just foot-gunny.
For example this lets you do:
```js
import { withCancel, signal } from './index.js';const ac = new AbortController();
setTimeout(() => ac.abort(), 10);
let count = 0;
await withCancel(async () => { // wrap with an IIFE if you don't have TLA enabled
try {
await timersPromises.setTimeout(60000, 0, { signal: signal() });
} catch (e) {
count++;
}
}, { signal: ac.signal });
strictEqual(count, 1);
```This means that instead of passing `signal` everywhere you can just call the `signal()` function and access the abort signal from context.
### License
MIT, or if you want I will let you use this code any other license if you ask :]
### Contributing
Please check this code out and tell me if it works for you or if you think it's a good idea.
### Code Of Conduct
This project uses the Contributor Covenant Code of Conduct. Reports go to benjamingr @ gmail