Skip to content

Instantly share code, notes, and snippets.

@dolohow
Created June 9, 2016 17:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dolohow/179d9e4b16aa8cc85033878cca1f1283 to your computer and use it in GitHub Desktop.
Save dolohow/179d9e4b16aa8cc85033878cca1f1283 to your computer and use it in GitHub Desktop.
package main
import (
"fmt"
"os"
"time"
)
func cancel(abort chan bool) {
fmt.Println("Exit (y/n)")
for {
var r int
fmt.Scanf("%c", &r)
switch r {
case 'y':
abort <- true
default:
abort <- false
}
}
}
func countDown(count chan int) {
for i := 10; i >= 0; i-- {
fmt.Printf("Currently doing step %d\n", i)
count <- i
time.Sleep(2000000000)
}
}
func main() {
count := make(chan int)
abort := make(chan bool)
go countDown(count)
go cancel(abort)
for {
select {
case i := <-count:
if i == 0 {
fmt.Println("konec")
os.Exit(0)
}
case a := <-abort:
if a {
os.Exit(0)
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment