3 ms·
Any other good articles on this, other than the proposal spec? 1. Is dispose run when the object is Garbage, or when the nearest scope exits? 2. Is `using` co
by seniorsassycat 3y ago
Any other good articles on this, other than the proposal spec?
1. Is dispose run when the object is Garbage, or when the nearest scope exits?
2. Is `using` const or let?
3. Is dispose looked up on declaration or before call?
4. Are chained resources disposed, or only the last?
5. What happens if the using resource is not disposable?
- bakkoting 3y ago1. Scope exit. 2. Const. 3. On declaration. 4. I don't know what "chained resource" means. If you mean multiple declarations within the same scope, they all get disposed, in LIFO order (even if disposing one of them throws). 5. An error when the `using` statement runs. (Unless the RHS itself is null, rather than an object without a `Symbol.dispose` method; this lets you have conditional declarations.)
- seniorsassycat 3y ago4 I mean `using x = a(b(), c())` if all functions return a disposable value will all three be disposed, or only the value returned by a and assigned to x?
- bakkoting 3y agoOnly the value assigned to x.
- seniorsassycat 3y ago5 is an interesting choice, what is the downside to allowing `using` on non-disposable values, treating it like a no op disposer? Otherwise a function that takes a maybe-disposable object parameter has to check if the symbol is defined, or the caller has to wrap the non disposable object
- bakkoting 3y agoBecause it's usually an error, and the benefit of catching the error cases outweighs the cost of losing that flexibility.
- seniorsassycat 3y agoWould be nice to include `guaranteeDisposable(x)` in the spec for cases you want to handle non-disposable values