by radq · 3y ago · 0 comments
using res = getResource();
const { x, y } = res; // ok
using { x, y } = getResource(); // error using getResource() as res; using someMutex.lock();
With the assignment syntax it's not obvious to me whether that's allowed.To be fair I don't see it not being supported either by the examples.
{
await using { connection } = getConnection();
// Do stuff with connection
} // Automatically closed!
edit: according to the ES proposal issues, this might be something that doesn't actually exist, on purpose (it's rather ambiguous as to what will be disposed of): https://github.com/tc39/proposal-explicit-resource-managemen...I did also click through to the proposal but didn't see that issue. It does seem like it's still unclear what's intentional or not.
What would that even mean? The binding in a `for-in` can only ever hold a string, which can't be disposable. With a `for` or `for-of` the binding can hold an object, which is something you could dispose of.
Much easier to not do it.
const using x = getX()
const {using prop1, prop2} = using getX()
void using getX()
// x, prop1 and 2 anonymous Xs to dispose
Instead of giving `using` the power / the burden of variable creation. This also solves `using mutex.lock()` mentioned elsewhere itt.