Documentation
¶
Overview ¶
Example (TickerImpl_Tick) ¶
ticker := New[int]() defer ticker.Stop() ticks := ticker.Ticks() ticker.Tick(42) next, stop := iter.Pull(ticks) fmt.Println(next()) stop()
Output: 42 true
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Restartable ¶
type TimeTicker ¶
func NewTimer ¶
func NewTimer(d time.Duration) TimeTicker
NewTimer creates a ticker that ticks on a timer. The timer is started on the first call to Ticks. If d == 0, the ticker internal timer is not started, and no ticks are dispatched.
Example ¶
This example illustrates the use of the ticker, that ticks every second during 2.5 seconds, and stops.
timer := NewTimer(time.Second)
time.AfterFunc(2500*time.Millisecond, timer.Stop)
startTime := time.Now()
for tick := range timer.Ticks() {
fmt.Println(tick.Sub(startTime).Round(time.Second))
}
Output: 0s 1s 2s
Click to show internal directories.
Click to hide internal directories.