Skip to content

defer

Useful when for script like things where cleanup should be done on fail or sucess no matter. You can call defer many times to register many deferred functions that will all be called when the function exits in any state.

Usage

const result = await defer(async (defer) => {
const fileHandle = await openFile("path/to/file");
defer(() => fileHandle.close());
// Perform operations on the file
return processFile(fileHandle);
});

Installation

Terminal window
npx atmx add helper defer