Created
February 20, 2015 15:28
-
-
Save yusuke024/61e25023c08175991870 to your computer and use it in GitHub Desktop.
Ticker in Go
This file contains 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 ( | |
"flag" | |
"io" | |
"log" | |
"os" | |
"strconv" | |
"time" | |
) | |
var ( | |
interval = flag.Int("i", 1000, "interval in milliseconds") | |
start = flag.Int("s", 1, "start sequence") | |
) | |
func main() { | |
flag.Parse() | |
ticker := time.NewTicker(time.Millisecond * time.Duration(*interval)) | |
defer ticker.Stop() | |
c := *start | |
for range ticker.C { | |
s := strconv.Itoa(c) | |
_, err := io.WriteString(os.Stdout, s+"\n") | |
if err != nil { | |
log.Fatal(err) | |
break | |
} | |
c++ | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment