lev.defer

lev

defer(fn)

Register an arbitrary cleanup function for the current task

Registers fn to run when the current coroutine finishes (success or error). Cleanups run in LIFO order, like Go's defer. Errors in cleanup functions are logged via log_error and don't prevent other cleanups from running. No-op outside lev.run() or from non-spawned coroutines.