Internally sleep is done with absolute time: if you call Sleep(n)
at time T
the program is scheduled not to wake up after n
time, but at time T + n
.
This is generally preferable because:
time usually does not flow backwards
due to OS scheduling delays a program which repeatedly sleeps may lag behind schedule indefinitely; using absolute time make it compensate for delays by sleeping for shorter intervals.
In your case, you just have to wait for a day for the program to start printing again. :D
Or set a time just a little in the past (say 15 sec), and see the program resuming after 15+2 sec.
PS. To clarify what happens with an example:
At 2016-08-25 16:27:12 the program calls time.Sleep(2 * time.Second)
The Go runtime schedules the goroutine to be woken up on 2016-08-25 at 16:27:14 and puts the goroutine to sleep
meanwhile ...
the user sets the system time to 2016-08-24 16:27:13
now the timeout is scheduled to expire one day and one second later.
This should not happen on systems, on which Go uses POSIX CLOCK_MONOTONIC or equivalent thereof.