Created
December 28, 2017 20:22
-
-
Save jonbodner/ab468310f2670737ba4fe277b5b143ac to your computer and use it in GitHub Desktop.
This file contains hidden or 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
func AddSlowly(a, b int) int { | |
time.Sleep(100 * time.Millisecond) | |
return a + b | |
} | |
func main() { | |
ch, err := Cacher(AddSlowly, 2*time.Second) | |
if err != nil { | |
panic(err) | |
} | |
chAddSlowly := ch.(func(int, int) int) | |
for i := 0; i < 5; i++ { | |
start := time.Now() | |
result := chAddSlowly(1, 2) | |
end := time.Now() | |
fmt.Println("got result", result, "in", end.Sub(start)) | |
} | |
time.Sleep(3 * time.Second) | |
start := time.Now() | |
result := chAddSlowly(1, 2) | |
end := time.Now() | |
fmt.Println("got result", result, "in", end.Sub(start)) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment