Defer early returns



examples/defer-early-return/defer_early_return.go
package main

import "fmt"

func main() {
    run(false)
    fmt.Println("--------")
    run(true)
}

func run(early bool) {
    fmt.Println("first")
    defer fmt.Println("do at the end")
    fmt.Println("second")
    if early {
        return
    }

    fmt.Println("last")
}

first
second
last
do at the end
--------
first
second
do at the end