defers
Defers are a programming mechanism for scheduling a piece of code to run later, typically when the surrounding function or scope exits. They are commonly used to guarantee resource cleanup and to separate cleanup logic from the main control flow, making code easier to read and less error-prone.
In languages that implement explicit defer constructs, the deferred action is registered and then executed when
Defers are closely related to other cleanup mechanisms such as finally blocks in imperative languages or scope-based
Common considerations include the order of execution (usually LIFO), the evaluation timing of arguments to the