README: defer
This commit is contained in:
@@ -172,7 +172,7 @@ Common Go syntax is already supported. Except for the following, which needs to
|
||||
* map (Very limited support)
|
||||
* panic (Limited support)
|
||||
* recover (Not supported yet)
|
||||
* defer (Not supported yet)
|
||||
* defer (Limited: defer in loops is not supported)
|
||||
* gc (Not supported yet)
|
||||
* chan (Not supported yet)
|
||||
* generics (Not supported yet)
|
||||
@@ -182,6 +182,7 @@ Here are some examples related to Go syntax:
|
||||
* [concat](_demo/concat/concat.go): define a variadic function
|
||||
* [genints](_demo/genints/genints.go): various forms of closure usage (including C function, recv.method and anonymous function)
|
||||
* [errors](_demo/errors/errors.go): demo to implement error interface
|
||||
* [defer](_demo/defer/defer.go): defer demo
|
||||
* [goroutine](_demo/goroutine/goroutine.go): goroutine demo
|
||||
|
||||
|
||||
|
||||
18
_demo/defer/defer.go
Normal file
18
_demo/defer/defer.go
Normal file
@@ -0,0 +1,18 @@
|
||||
package main
|
||||
|
||||
func f(s string) bool {
|
||||
return len(s) > 2
|
||||
}
|
||||
|
||||
func main() {
|
||||
defer func() {
|
||||
println("hi")
|
||||
}()
|
||||
if s := "hello"; f(s) {
|
||||
defer println(s)
|
||||
} else {
|
||||
defer println("world")
|
||||
return
|
||||
}
|
||||
defer println("bye")
|
||||
}
|
||||
Reference in New Issue
Block a user