Skip to content

Instantly share code, notes, and snippets.

@gertcuykens
Last active August 29, 2015 14:08
Show Gist options
  • Save gertcuykens/6f9cfcd82ec7793a7534 to your computer and use it in GitHub Desktop.
Save gertcuykens/6f9cfcd82ec7793a7534 to your computer and use it in GitHub Desktop.
golang
package main
import "fmt"
func main() {
ch := make(chan int)
go fibs(ch)
for i := 0; i < 20; i++ {
fmt.Println(<-ch)
}
ch <- 0
}
func fibs(ch chan int) {
i, j := 0, 1
for {
select {
case ch <- j:
i, j = j, i+j
case <- ch :
return
}
}
}
c := make(chan os.Signal, 1)
signal.Notify(c, os.Interrupt)
go func() {
<-c
log.Print("deleting database db")
os.RemoveAll("db")
defer os.RemoveAll("db")
os.Exit(1)
}()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment