running 2 goroutines


👍 go run spinner.go
/
(after a few seconds) =>
Fib(45) = 1134903170

👍 cat spinner.go 
package main

import (
  "time"
  "fmt"
)

func main() {
  go spinner(100 * time.Millisecond)
  const n = 45
  fibN := fib(n)
  fmt.Printf("\rFib(%d) = %d\n",n,fibN)
}

func spinner(delay time.Duration) {
  for {
    for _, r := range `-\|/` {
      fmt.Printf("\r%c", r)
      time.Sleep(delay)
    }
  }
}

func fib(x int) int {
  if x < 2 {
    return x
  }
  return fib(x-1) + fib(x-2)
}

    

ch8.1 Goroutines p218/237 of