Tick
Produces a command at an interval independent of the system clock at the given duration. That is, the timer begins precisely when invoked, and runs for its entire duration.The duration to wait before the tick fires.
A function that receives the time at which the tick occurred and returns a message.
Returns
Returns aCmd that waits for the specified duration and then sends the message returned by the provided function.
Important Note
Tick sends a single message and won’t automatically dispatch messages at an interval. To do that, you’ll want to return another Tick command after receiving your tick message.
Example
Every
A command that ticks in sync with the system clock. So, if you wanted to tick with the system clock every second, minute or hour you could use this. It’s also handy for having different things tick in sync.The duration interval to align with the system clock.
A function that receives the time at which the tick occurred and returns a message.
Returns
Returns aCmd that waits until the next system clock boundary and then sends the message returned by the provided function.
Clock Synchronization
Because we’re ticking with the system clock, the tick will likely not run for the entire specified duration. For example, if we’re ticking for one minute and the clock is at 12:34:20, then the next tick will happen at 12:35:00, 40 seconds later.Important Note
Every sends a single message and won’t automatically dispatch messages at an interval. To do that, you’ll want to return another Every command after receiving your tick message.
Example
Tick vs Every
Use Tick when:
- You need precise timing independent of the system clock
- You want consistent intervals regardless of when the command starts
- You’re implementing timeouts or delays
Use Every when:
- You want to synchronize with the system clock
- You need multiple timers to tick at the same time
- You’re implementing clock-based updates (every hour, minute, etc.)
Timing Difference Example
If the current time is 12:34:45:Tick(time.Minute, ...)will fire at 12:35:45 (exactly 60 seconds later)Every(time.Minute, ...)will fire at 12:35:00 (at the next minute boundary, only 15 seconds later)