-
-
Save patio11/bc883d566778c323742432c203e69541 to your computer and use it in GitHub Desktop.
GoLang's understanding of what timer.Reset() should do does not match mine
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 "time" | |
import "fmt" | |
func main() { | |
longTimer := time.NewTimer(1 * time.Second) | |
time.Sleep(5 * time.Second) | |
fmt.Println("We agree that longTimer has fired, right? That will become important in the future.") | |
longTimer.Reset(1 * time.Second) | |
shortTimer := time.NewTimer(5 * time.Millisecond) | |
select { | |
case <-shortTimer.C: | |
fmt.Println("This is the behavior we expect: 1 second is longer than 5ms, 'by a lot.'") | |
case <-longTimer.C: | |
fmt.Println("This is the behavior GoLang delivers: Reset() did not actually reset the timer.") | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment