Prototype: withResource(resource, body) calls body(resource), then resource.close() exactly once before returning or throwing. This stage is synchronous. If body succeeds, return its value; if either part fails, propagate it. If both fail, throw AggregateError containing the exact original thrown values [bodyError, closeError] in that order, without replacing either object.

Final: usingResource(open, body) asynchronously acquires the resource by awaiting open(), awaits body(resource), and awaits resource.close() exactly once. Apply the same result/error policy. If acquisition fails, never invoke body or close. Do not resolve or reject before cleanup completes, including when body has already failed.

Complete the exported stubs in exercise.mjs. The prototype and final stages have separate checks.

Shell
node main.mjs --stage prototype
node main.mjs --stage final

Use Node.js 20+ locally, or the website's browser worker. Tests are standard-library only and check the documented behavior; they do not prove performance or force garbage collection.

Drag or use the arrow keys to resize. Home collapses the question; End collapses the editor. Enter or double-click resets the split.
Loading editor…
No results yet.

Complete the starter code, then run the checks.
Results and errors will appear here.