Исходники и презентации
This commit is contained in:
28
lessons/functions/defer_calculating/main.go
Normal file
28
lessons/functions/defer_calculating/main.go
Normal file
@ -0,0 +1,28 @@
|
||||
package main
|
||||
|
||||
import "fmt"
|
||||
|
||||
// Need to show solution
|
||||
|
||||
const (
|
||||
StatusOk = "ok"
|
||||
StatusError = "error"
|
||||
)
|
||||
|
||||
func notify(status string) {
|
||||
fmt.Println(status)
|
||||
}
|
||||
|
||||
func process() {
|
||||
var status string
|
||||
defer func(s string) {
|
||||
notify(s)
|
||||
}(status)
|
||||
|
||||
// processing..
|
||||
status = StatusError
|
||||
}
|
||||
|
||||
func main() {
|
||||
process()
|
||||
}
|
||||
Reference in New Issue
Block a user