defer
defer(fn) registers a cleanup function to run immediately after the top-level hook exits. Essential for preventing zombie processes and memory leaks.
Signature
Section titled “Signature”defer(fn)
syncParameters
Section titled “Parameters”| Param | Type | Description |
|---|---|---|
fn |
function | Cleanup function to call after the hook exits |
Returns
Section titled “Returns”None.
Example
Section titled “Example”function override_fetch(request, ctx) local browser = cdp.launch({ headless = true }) defer(function() browser:close() end) -- Always closes
local page = browser:attach() page:open(request.url) return { status = 200, body = page:content() }endSee Also
Section titled “See Also”- Lifecycle - Full lifecycle documentation