Question presented to candidate: "If you declare using r1 = resource1, then using r2 = resource2 inside a block, and an error is thrown right after β do the resources still get cleaned up? And in what order?"
What a strong answer should cover:
- π Interview term:
usingdeclaration β declares a resource that must implement[Symbol.dispose](); the engine genuinely, automatically calls that method when the enclosing block exits β normally OR via an earlyreturn/break/thrown error. - π Interview term: the real, direct answer to the prompt's first question β verified directly: a real error thrown right after declaring a
usingresource genuinely still triggers disposal β the resource's[Symbol.dispose]ran correctly BEFORE the error propagated to a surrounding catch block. - π Interview term: the real, direct answer to the prompt's order question β verified directly with 3 real resources: disposal genuinely happens in strict reverse declaration order β the LAST-declared resource is disposed FIRST, mirroring a real, standard stack-unwinding discipline.
- π Interview term:
await usingβ the async counterpart, for a resource implementing[Symbol.asyncDispose]()instead β verified directly: the surroundingasync functiongenuinely does not fully resolve until the async disposal itself has been correctlyawaited. - A precise answer names
DisposableStack/AsyncDisposableStackas the real, companion container types this proposal also introduces β a stack-based way to register MULTIPLE disposable resources together programmatically, beyond individualusingdeclarations β confirmed directly to exist as real, defined globals alongsideSymbol.dispose/Symbol.asyncDispose.
Clarifying questions expected:
- None β this is a definitional/technical question; directly answering both halves of the prompt (disposal-on-error, and reverse order) with real proof is the strong signal.
Code / implementation expected: Yes β real proof of both disposal-on-error and strict reverse-order disposal with 3 real resources is the clearest, most convincing demonstration.