Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

_content/tour/flowcontrol/defer.go: add example for arguments eager evaluation #284

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion _content/tour/flowcontrol.article
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ This construct can be a clean way to write long if-then-else chains.

* Defer

A defer statement defers the execution of a function until the surrounding
A `defer` statement defers the execution of a function until the surrounding
function returns.

The deferred call's arguments are evaluated immediately, but the function call
Expand Down
7 changes: 6 additions & 1 deletion _content/tour/flowcontrol/defer.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,13 @@ package main

import "fmt"

func helper() string {
fmt.Println("helper")
return "world"
}

func main() {
defer fmt.Println("world")
defer fmt.Println(helper())

fmt.Println("hello")
}