Skip to content

defer

The defer() function registers a cleanup callback that the flow runtime executes after the flow ends. It is useful to release resources or run side effects after a return or a break.

Interactive example

Syntax

typescript
function defer<
	GenericOutput extends unknown
>(
	theFunction: () => GenericOutput
): Generator<Defer<GenericOutput>, undefined>

Parameters

  • theFunction: Cleanup callback to run when the flow finishes.

Return value

A generator yielding a defer effect. The callback result itself is not returned by the flow.

See also

  • finalizer - Registers another end-of-flow callback
  • run - Executes deferred callbacks when the flow completes

Released under the MIT license.