Defer
Defer schedules cleanup code to run when the current scope exits, regardless of how it exits - normal completion, early return, fail, or error propagation. Multiple defers execute in reverse (LIFO) order.
|
|
Multiple defers run in reverse (LIFO) order. |
|
Defer blocks can contain multiple statements. |
|
Defer in a loop runs at each iteration end. |
|
$ pyr run defer.pyr start work cleanup --- body first second third --- main work step 1 step 2 --- iteration 0 cleanup 0 iteration 1 cleanup 1 iteration 2 cleanup 2 |