demo · v134
using
using lock = mutex.acquire() calls lock[Symbol.dispose]() when the block exits — guaranteed, before the exception propagates. The buttons run real using blocks against instrumented disposable resources and log lifecycle to show the LIFO dispose order and exception-safe cleanup.
probing Symbol.dispose...
Try it
The code
function acquire(name) {
return {
name,
[Symbol.dispose]() { console.log("releasing", name); }
};
}
function example() {
using lock = acquire("primary");
// ... use lock ...
} // lock is disposed HERE