一宫静、知識(shí)點(diǎn)走净、
1券时、用到go 關(guān)鍵字定位
2、用到defer 延后處理最終執(zhí)行
3伏伯、內(nèi)置函數(shù)說(shuō)明:
二橘洞、代碼
、说搅、炸枣、
package main
import (
"fmt"
"time"
)
func serve(ch <-chan int) {
for val := range ch {
go handle(val)
}
}
func handle(x int) {
defer func() {
if err := recover(); err != nil {
fmt.Println("work failed at :", err)
}
}()
if x == 4 {
panic(x)
}
fmt.Println("work successed at :", x)
}
func main() {
var ch = make(chan int, 6)
for i := 1; i <= 6; i++ {
ch <- i
}
close(ch)
go serve(ch)
time.Sleep(time.Millisecond * 100)
}
、蜓堕、抛虏、
三、圖片及運(yùn)行結(jié)果