forked from jincheng9/go-tutorial
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
199 additions
and
33 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
// named_return1.go | ||
package main | ||
|
||
import "fmt" | ||
|
||
func test() (done func()) { | ||
return func() { fmt.Println("test"); done() } | ||
} | ||
|
||
func main() { | ||
done := test() | ||
// 下面的函数调用会进入死循环,不断打印test | ||
done() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
// named_return3.go | ||
package main | ||
|
||
import "fmt" | ||
|
||
func test() (done func()) { | ||
done = func() { fmt.Println("done") } | ||
return func() { fmt.Println("test"); done() } | ||
} | ||
|
||
func main() { | ||
done := test() | ||
// 下面的函数调用会进入死循环,不断打印test | ||
done() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
// named_return2.go | ||
package main | ||
|
||
import "fmt" | ||
|
||
var print = fmt.Println | ||
|
||
func aaa() (done func(), err error) { | ||
return func() { print("aaa: done") }, nil | ||
} | ||
|
||
func bbb() (done func(), _ error) { | ||
f, err := aaa() | ||
return func() { print("bbb: surprise!"); f() }, err | ||
} | ||
|
||
func main() { | ||
done, _ := bbb() | ||
// 下面的函数调用会正常结束,不会进入死循环 | ||
done() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package main | ||
|
||
func aaa() (done func()) { | ||
return func() { print("aaa: done") } | ||
} | ||
|
||
func bbb() (done func()) { | ||
done = aaa() | ||
return done | ||
} | ||
|
||
func main() { | ||
done := bbb() | ||
// 下面的函数调用会正常结束,打印"aaa: done" | ||
done() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters