-
Notifications
You must be signed in to change notification settings - Fork 34
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How does one register *what* to dispose? #156
Comments
I am confused about what distinction you are drawing between "implementing their own disposables, ad hoc" vs "a consistent API was available for people to register teardowns". Do you just mean that you want it to be easy for users of something which is not disposable to set up disposal? That's offered by using stack = new DisposableStack();
const reader = stack.adopt(createReader(), reader => reader.releaseLock()); or using stack = new DisposableStack();
console.log("enter");
stack.defer(() => console.log("exit")); If that's not what you're thinking of, can you give an example of the sort of thing you mean? (DisposableStack will let you register multiple things to get disposed, which sounds like it's an answer to your "users will need to register one or more things that need to happen during disposal" point.)
I want to have a cancel-on-dispose AbortController, which sounds like an answer to this question? That would let you do using controller = new AbortController.AutoAbort();
let pages = await Promise.all(urls.map(url => fetch(url, { signal: controller.signal }));
// automatically cancels outstanding requests if any request fails It will need to be pursued in HTML, though; I've been waiting for implementations of this proposal to begin before I start pushing the work there. |
Hmm.. maybe I missed some of this because I was looking on my phone. I'll close this issue until I re-read. |
This seems like it's only half a spec. While it might unify implicit disposal of resources, it doesn't do anything to address how those resources should be registered for disposal. It also means that everyone is going to be implementing their own disposables, ad hoc, so they can be used with this
using
statement. It would be so much better, in my opinion, if a consistent API was available for people to register teardowns and get a disposable.Even worse, how are people going to tie this to the only "universal" cancellation mechanism,
AbortSignal
?I'm concerned we're building a mess here instead of a cohesive developer experience.
From my experience with RxJS:
As best I can tell, this proposal handles number 1 only?
The text was updated successfully, but these errors were encountered: