This commit is contained in:
Alexander Pivkin 2025-12-29 10:35:19 +03:00
parent 83bbe32525
commit 1072400433
2 changed files with 27 additions and 1 deletions

View File

@ -13,4 +13,7 @@ func main() {
f := square() f := square()
fmt.Println(f()) fmt.Println(f())
fmt.Println(f()) fmt.Println(f())
fmt.Println(f())
fmt.Println(f())
fmt.Println(f())
} }

View File

@ -1 +1,24 @@
package defer package main
import (
"fmt"
"time"
)
func logger(s string) func() {
fmt.Printf("Enter in %s\n",s)
now := time.Now()
return func () {
fmt.Printf("Time elapsed %s\n",time.Since(now))
fmt.Printf("Exit from func %s\n",s)
}
}
func SlowOP() {
defer logger("SlowOP")()
time.Sleep(2*time.Second)
}
func main() {
SlowOP()
}