Skip to content

Instantly share code, notes, and snippets.

@jordanorelli
Created April 11, 2012 01:43
Show Gist options
  • Save jordanorelli/2356279 to your computer and use it in GitHub Desktop.
Save jordanorelli/2356279 to your computer and use it in GitHub Desktop.
whyyyyyyy
package main
import (
"fmt"
"os"
"os/signal"
"syscall"
)
func main() {
count := 0
quit := make(chan os.Signal)
signal.Notify(quit, syscall.SIGINT)
for {
select {
case <-quit:
goto STANLEY
default:
count += 1
fmt.Println(count)
}
}
STANLEY:
fmt.Println("done")
}
package main
import (
"fmt"
"os"
"os/signal"
"syscall"
)
func main() {
count := 0
quit := make(chan os.Signal)
signal.Notify(quit, syscall.SIGINT)
for {
select {
case <-quit:
break
default:
count += 1
fmt.Println(count)
}
}
fmt.Println("done")
}
package main
import (
"fmt"
"os"
"os/signal"
"syscall"
)
func count(quit chan bool) {
var count int
for {
select {
case <-quit:
break
default:
count += 1
fmt.Println(count)
}
}
}
func main() {
quit := make(chan bool)
sig := make(chan os.Signal)
signal.Notify(sig, syscall.SIGINT)
go count(quit)
<-sig
quit <- true
fmt.Println("done")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment