Created
October 8, 2015 20:12
-
-
Save montanaflynn/118f51866f1c0dec61a8 to your computer and use it in GitHub Desktop.
Listen for SIGINFO to report progress
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" | |
"os" | |
"os/signal" | |
"syscall" | |
"time" | |
) | |
func main() { | |
var i int | |
sigs := make(chan os.Signal, 1) | |
signal.Notify(sigs, syscall.SIGINFO) | |
go func() { | |
for { | |
<-sigs | |
fmt.Printf("Processed up to: %d\n", i) | |
} | |
}() | |
// simulate doing lots of hard work for 60 seconds | |
go func() { | |
for { | |
i++ | |
time.Sleep(500 * time.Millisecond) | |
} | |
}() | |
time.Sleep(60 * time.Second) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment