-
Notifications
You must be signed in to change notification settings - Fork 22
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
Use time.NewTimer()
instead of time.After()
#56
Conversation
For efficiency, cancel time.Timer after no longer needed. See https://pkg.go.dev/time#After
Very interesting, I didn't know
Out of curiosity I wanted to see it for myself so I added profiling in #57 and sure enough:
Hope you don't mind I updated your PR to use |
@andreykaipov no problem on the updated PR. But I am curious about:
Thank you for the merge. |
My apologies -- I thought the motivation of the PR was only for the timer memory efficiency. Sorry for discarding your timeout changes without any comment. I suppose I was concerned about backwards compatibility for anybody that might've been using a zero timeout already. However thinking about it now... that'd be impossible since immediately timing out wouldn't allow for the connection to establish in the first place. I'm not against adding a way to specify an indefinite timeout but out of curiosity does using a really large timeout (e.g. 24 hours) not meet your needs? |
@andreykaipov |
For efficiency, cancel time.Timer after no longer needed. See https://pkg.go.dev/time#After
Note on behavior change:
timeout duration <= 0 now means waiting forever instead of immediately times out..