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

Comments

Projects
None yet
4 participants
@Sajmani
Copy link
Contributor

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

This comment has been minimized.

Copy link

commented Nov 25, 2012

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

This comment has been minimized.

Copy link

commented Nov 25, 2012

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

This comment has been minimized.

Copy link
Contributor Author

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

This comment has been minimized.

Copy link

commented Nov 26, 2012

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

This comment has been minimized.

Copy link
Contributor

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

This comment has been minimized.

Copy link
Contributor

commented Dec 10, 2012

Comment 6:

Labels changed: added size-l.

@rsc

This comment has been minimized.

Copy link
Contributor

commented Dec 30, 2012

Comment 7:

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

@adg

This comment has been minimized.

Copy link
Contributor

commented Jan 17, 2013

Comment 8:

This issue was closed by revision 44ff17e.

Status changed to Fixed.

@Sajmani Sajmani added fixed labels Jan 17, 2013

@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

This issue was closed.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
You can’t perform that action at this time.