public
Created

Deferred closure example $ go run deferClosure.go The deferred scope 42 The deferred A-call 42 Back in the main method 42

  • Download Gist
deferClosure.go
Go
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
package main
 
import "fmt"
 
func A(x int) {
fmt.Println("The deferred A-call", x)
}
 
func B() int {
theAnswer := 42
defer func() {
fmt.Println("The deferred scope", theAnswer)
A(theAnswer)
}()
return theAnswer
}
 
func main() {
fmt.Println("Back in the main method", B())
}

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.