Skip to content
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

time: add (*Timer).Reset(d Duration) #4412

Closed
Sajmani opened this issue Nov 19, 2012 · 8 comments
Closed

time: add (*Timer).Reset(d Duration) #4412

Sajmani opened this issue Nov 19, 2012 · 8 comments
Milestone

Comments

@Sajmani
Copy link
Contributor

Sajmani commented Nov 19, 2012

Some use cases for timers require extending the timer's deadline or resetting it to fire
again.  Implementing this using the existing time functions NewTimer and AfterFunc is
somewhat awkward and error-prone.  Instead, let's add:
  // Reset resets the time remaining on the timer to d.
  func (*Timer) Reset(d Duration)
@gopherbot
Copy link

Comment 1 by eric.d.eisner:

Is it implied that this function would also clear the channel's queue? Otherwise a Reset
followed by a channel read could fire immediately, which sounds like surprising behavior.

@gopherbot
Copy link

Comment 2 by eric.d.eisner:

Or maybe to encourage reusing Timers in recurring timeouts, the signature could be:
func (t *Timer) Reset(d Duration) <-chan Time
Which would just return the same channel every time.

@Sajmani
Copy link
Contributor Author

Sajmani commented Nov 26, 2012

Comment 3:

I don't think we should make any guarantees about the channel contents, since this is
racy.  But perhaps Reset should expose the same information as Stop, that is, a boolean
indicating whether the Reset happened before the timer fired.  But I would omit even
that bit for now, until there's a demonstrated need.

@gopherbot
Copy link

Comment 4 by eric.d.eisner:

Ensuring the channel is cleared could be made unracy, but the non-blocking channel read
would have to move into runtime under the global timer lock.

@rsc
Copy link
Contributor

rsc commented Nov 26, 2012

Comment 5:

It is probably worth returning the bool.
I strongly prefer not to muck with channel internals to undo a send.

@rsc
Copy link
Contributor

rsc commented Dec 10, 2012

Comment 6:

Labels changed: added size-l.

@rsc
Copy link
Contributor

rsc commented Dec 30, 2012

Comment 7:

Labels changed: added priority-later, removed priority-triage.

@adg
Copy link
Contributor

adg commented Jan 17, 2013

Comment 8:

This issue was closed by revision 44ff17e.

Status changed to Fixed.

@Sajmani Sajmani self-assigned this Jan 17, 2013
@rsc rsc added this to the Go1.1 milestone Apr 14, 2015
@rsc rsc removed the go1.1 label Apr 14, 2015
@golang golang locked and limited conversation to collaborators Jun 24, 2016
@rsc rsc unassigned Sajmani Jun 22, 2022
This issue was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants