go: duration loop

Here is a simple duration loop go program https://play.golang.org/p/ly9U9EUr2of

package main

import (
	"fmt"
	"time"
)

func main() {
	duration := time.Second *10
	fmt.Println("Hello, duration loop "+duration.String()+" long")
	
	t1 := time.Now()
	
	for t2:= time.Now(); t2.Sub(t1) < duration; t2 = time.Now(){
	   	fmt.Println(t2.String())
		time.Sleep(time.Second)
	
	}
}

This entry was posted in golang, workday. Bookmark the permalink.

Leave a Reply