mirror of
https://github.com/crazybber/awesome-patterns.git
synced 2024-11-25 22:36:05 +03:00
added block example
This commit is contained in:
parent
749f730fd8
commit
3919cfa894
@ -23,7 +23,19 @@ func deferInsideLoop() {
|
||||
}
|
||||
}
|
||||
|
||||
// The deferred func above will only run when the func ends not when the deferred func’s surrounding block ends
|
||||
// (the area inside curly braces containing the defer call). As seen in the example code, you can create separate blocks just using curly braces.
|
||||
func block() {
|
||||
{
|
||||
defer func() {
|
||||
fmt.Println("block: defer runs")
|
||||
}()
|
||||
}
|
||||
fmt.Println("main: ends")
|
||||
}
|
||||
|
||||
func main() {
|
||||
// nilFuncDefer()
|
||||
deferInsideLoop()
|
||||
// deferInsideLoop()
|
||||
block()
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user