defer.go 280 B

1234567891011121314151617
  1. package main
  2. import "fmt"
  3. func main() {
  4. Function1()
  5. }
  6. func Function1() {
  7. fmt.Printf("In Function1 at the top\n")
  8. defer Function2()
  9. fmt.Printf("In Function1 at the bottom!\n")
  10. }
  11. func Function2() {
  12. fmt.Printf("Function2: Deferred until the end of the calling function!")
  13. }