3 ms·
> The Clock interface also exposes functions like time.After(), which should in my opinion never be used in production code, as they don't support efficient can
by zeroxfe 6y ago
> The Clock interface also exposes functions like time.After(), which should in my opinion never be used in production code, as they don't support efficient cancelation.
Can you expand on this? I find time.After super useful for time arithmetic in control flow, like checking for expiry, validating leases, etc.
- EdSchouten 6y agoKeep in mind that there are two functions called After(). One is a method of time.Time and can be used to compare timestamps. That’s the one you are likely talking about, and is perfectly fine to use! I’m talking about the free function After() that’s part of the time package: https://golang.org/pkg/time/#After https://golang.org/pkg/time/#After That one can be used to create a channel that triggers after a certain amount of time. The reason you shouldn’t be using that one is because you can’t clean it up before it triggers. This means that any code that bails out early ends up leaking memory temporarily.
- zeroxfe 6y agoAh, gotcha -- I was thinking of the timestamp comparison method. (Agreed about the other case.)