Open mchirico opened 3 years ago
mchirico, Thanks for opening this issue!
package main
import (
"fmt"
"sync"
"time"
)
type MF struct {
l int
sync.Mutex
}
func (mf *MF) mfmt(txt string, timeSleep int) {
mf.Mutex.Lock()
defer mf.Mutex.Unlock()
for i := 0; i < mf.l; i++ {
fmt.Printf("\b") // backspace
}
mf.l = len(txt)
fmt.Printf("%s", txt)
time.Sleep(time.Duration(timeSleep) * time.Millisecond)
}
func main() {
m := &MF{}
for i := 0; i < 1000; i++ {
now := time.Now()
timeString := fmt.Sprintf("%02d:%02d:%02d ", now.Hour(), now.Minute(), now.Second())
m.mfmt(timeString, 100)
}
}
func (mf *MF) mfmt(txt string, timeSleep int) { mf.Mutex.Lock() defer mf.Mutex.Unlock()
for i := 0; i < mf.l; i++ {
fmt.Printf("\b") // backspace
}
mf.l = len(txt)
fmt.Printf("%s", txt)
time.Sleep(time.Duration(timeSleep) * time.Millisecond) **<--- clock moves per** millisecond
} func main() {
m := &MF{}
for i := 0; i < 1000; i++ {
now := time.Now()
timeString := fmt.Sprintf("%02d:%02d:%02d ", now.Hour(), now.Minute(), now.Second())
m.mfmt(timeString, 100)
}
} main function prints out the hour, minutes, and seconds
so why wont time.Sleep(time.Duration(timeSleep) * time.now.Hour()) work
Show the work for Day 12...