Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
28
Task/Handle-a-signal/Go/handle-a-signal.go
Normal file
28
Task/Handle-a-signal/Go/handle-a-signal.go
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"os/signal"
|
||||
"time"
|
||||
)
|
||||
|
||||
func main() {
|
||||
start := time.Now()
|
||||
k := time.Tick(time.Second / 2)
|
||||
sc := make(chan os.Signal, 1)
|
||||
signal.Notify(sc, os.Interrupt)
|
||||
for n := 1; ; {
|
||||
// not busy waiting, this blocks until one of the two
|
||||
// channel operations is possible
|
||||
select {
|
||||
case <-k:
|
||||
fmt.Println(n)
|
||||
n++
|
||||
case <-sc:
|
||||
fmt.Printf("Ran for %f seconds.\n",
|
||||
time.Now().Sub(start).Seconds())
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue