Closed ClementNerma closed 1 year ago
It works fine, but doesn't run the dispose method.
It works fine, but doesn't run the dispose method.
Isn't this a footgun? There will 100% be cases where someone forgets to use using
and uses let
or const
instead, and gets bugs because the resource hasn't been disposed of (like a database connection or a file handle not closing itself), which could be hard to debug especially in async. scenarios.
The proposal is called "explicit resource management", so like many other parts of programming, yes, if you forget to take the right steps, the right thing won't happen.
This seems like it may be a duplicate of #159.
I think it can be considered a duplicate yes, so I'm closing this in favor of #159
This may have been answered already, but I can't find anything on this, so here I go:
Let's say we have a function returning an object that implements the
[Symbol.dispose]()
method. The normal usage isusing x = disposable();
At the end of the block, the dispose method is called.
But what happens if we write
let x = disposable();
? Orconst x = disposable();
? Is this a runtime error / type error, does this run normally without running the dispose method at the end of the scope?This seems like a basic question so I'm pretty sure it's been answered somewhere already but I didn't manage to find anything on this question, so I'd appreciate if someone can explain this to me :)