Skip to content

Instantly share code, notes, and snippets.

@tristanwietsma
Created September 16, 2013 17:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save tristanwietsma/6583700 to your computer and use it in GitHub Desktop.
Save tristanwietsma/6583700 to your computer and use it in GitHub Desktop.
Deferred closure example $ go run deferClosure.go The deferred scope 42 The deferred A-call 42 Back in the main method 42
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())
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment