Last active
August 29, 2015 14:08
-
-
Save gertcuykens/6f9cfcd82ec7793a7534 to your computer and use it in GitHub Desktop.
golang
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
} | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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