Skip to content

Commit 65ecbc1

Browse files
committed
add defer arg eager eval example
1 parent 3d551ff commit 65ecbc1

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

_content/tour/flowcontrol.article

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ This construct can be a clean way to write long if-then-else chains.
153153

154154
* Defer
155155

156-
A defer statement defers the execution of a function until the surrounding
156+
A `defer` statement defers the execution of a function until the surrounding
157157
function returns.
158158

159159
The deferred call's arguments are evaluated immediately, but the function call

_content/tour/flowcontrol/defer.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,13 @@ package main
44

55
import "fmt"
66

7+
func helper() string {
8+
fmt.Println("helper")
9+
return "world"
10+
}
11+
712
func main() {
8-
defer fmt.Println("world")
13+
defer fmt.Println(helper())
914

1015
fmt.Println("hello")
1116
}

0 commit comments

Comments
 (0)