-
Notifications
You must be signed in to change notification settings - Fork 59
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Make usable zero value of clockwork.Clock #61
Comments
|
I suggest to use zero value of for example wrapper with same behavior: https://gist.github.com/rekby/a7f3e679e47604b28d22c7736d0ff388 |
@rekby this is certainly an interesting proposal, but even your wrapper relies on an interface for allowing alternate implementations, so we can't just throw it away. We can, however, add such a wrapper to the library (called Let me play with that wrapper of yours a little. |
Gotcha, your issue title "usable zero value" confused me. I think I now understand that you are asking for custom clocks. Changing this interface to a struct would break most users, because the interface is passed as a <pointer, type> whereas the struct would be passed by value copy unless users changed it to a pointer to struct throughout their code base. It is unlikely that change will be made. If you want to accomplish what you are seeking, |
@DPJacques I believe this is what @rekby is asking for: type MyStruct struct{
Clock clockwork.Clock
}
var mystruct MyStruct
// Use Clock without initialization
mystruct.Clock.Now() It should be possible with an alternate name, but we may have to change the real clock implementation to use values instead of pointers (which doesn't sound all that bad TBH). |
Gotcha, the code helps understand a bit. I maintain my position that I don't think avoiding initialization is a compelling requirement, in light of:
Requiring the code block above to be the following does not seem egregious to me:
And I admit I'd be ok requiring users with strong opinions to roll their own wrapper if it means the API stays clean. Not necessarily my call, just my $0.02 :) |
DefaulClock is a Clock implementation that does not require initialization. It automatically falls back to calling the real clock. Potential fix for #61 Signed-off-by: Mark Sagi-Kazar <[email protected]>
See the linked PR. I myself is not convinced yet that this belongs to this package, but I wanted to play with the idea. |
Totally makes sense. I'm glad I am not the only one who needs to code a bit to convince themselves if something is a good idea or not 😄 I did my best to provide reasoning for my stance above. I don't think I could do any better than the PR you put out, although that reinforces my position: it feels like a lot of code for not a lot of benefit :/ |
Closing this out since |
for this - change clockwork.Clock type from interface to struct or pointer with call system time functions by default (for zero value).
It allow make my own types usable with zero value without wrap time calls in my code.
The text was updated successfully, but these errors were encountered: