Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Sadly it needs a language feature that doesn't exist yet


What do you mean? You can definitely already wrap that into a Symbol.dispose-keyed object and use it via `using`


`using` is not a thing in JS


Uh, you are wrong. It absolutely is a thing and it has been in your browser and Node for longer than a year.

https://github.com/nodejs/node/pull/48518 https://github.com/tc39/proposal-explicit-resource-managemen...


s/yet/thankfully/. We don’t need it cause it solves no real problem and the solution is loaded with implicit complexity.


'using' fixes having to do cleanup in a finally {} handler, which you can a) forget, and b) often messes up scoping of variables as you need to move them outside the 'try' block.


It also creates additional finalization semantics for a using-ed value. Which has all sorts of implications. lock.do(async (lock) => {work}) is a similar construct - a scope-limited aquisition that requires nothing special.

Catch/finally not sharing a scope with try is a repeated mistake, that I surely agree with!




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: