//使用defer来预防协程发生错误 package main import ( "fmt" "time" ) func Spinner(delay time.Duration){ for { for _,r:= range `-|/` { fmt.Printf(" %c",r); time.Sleep(delay); } } } func fib(x int ) int { if x <2 { return x } return fib(x-1) + fib(x-2); } func main (){ go Spinner(100 * time.Millisecond); const n=80; fibN:=fib(n); fmt.Println(fibN); }
这是运行结果