// What does using actually clean up? // Teaching excerpts; see the explanation and boundaries on the episode page. // It calls a method when the block ends. const resource = { [Symbol.dispose]() { events.push("dispose"); } }; // Return does not skip cleanup. function job() { using r = resource; events.push("work"); return "done"; } events.push(job()); // The compiler adds helpers and finally. // Emitted structure, shortened try { // Register resource and do work } finally { __disposeResources(env_1); } // No dispose method? Use try finally. const file = openFile(); try { return read(file); } finally { file.close(); }