I'm not convinced that the docs quite cover the case I am looking, so
I am posting here.

https://golang.org/pkg/time/#Timer.Reset says "This should not be done
concurrent to other receives from the Timer's channel" but it's not
clear what the repercussions are.

In our case, I have a function to be run periodically, on a timer, but
it can be run manually too.  When run manually, I want to push the
timer out (restart the period).

I have a goroutine doing:

```
        for {
                select {
                case <-stop:
                        pr.stop()
                        return
                case <-timer.C:
                        run()
                }
        }
```

deep inside run(), we have:

```
timer.Stop()
timer.Reset(period)
```

I understand that I could lose the race and deliver on timer.C _just
before_ this runs, and that is fine.  What I am seeking to know is
whether this is considered "safe"?  The receive is running
concurrently to the Reset().  Will this cause problems inside Timer,
beyond the potential "extra" delivery?  Do I need to break the loop
and stop receiving on it while the Reset() happens?

Tim

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to