Timers and tickers¶
Category: Async · Status: stub · Lessons: chapter 06, Async (planned)
One line: A runtime facility that fires once after a delay, or repeatedly at an interval, and delivers it as a callback, a value on a channel, or something to await.
Also called: ticker, interval, setTimeout.
How it connects¶
- See also: Event loop, Timeout
In each language¶
| Rust | Tokio's time ↗ module: sleep, interval and timeout |
| Go | time.Timer ↗ and time.Ticker ↗, each delivering on a channel |
| Java | ScheduledExecutorService ↗ runs tasks after a delay or periodically |
| Python | loop.call_later ↗ on the event loop, and threading.Timer ↗ for threads |
| C# | PeriodicTimer ↗, whose ticks are awaited |
| JavaScript | setTimeout ↗ and setInterval |
| The operating system | timerfd_create ↗ makes a timer readable as a file descriptor, so an event loop can wait on it |
Where to read more¶
- In a sibling library: Go: A timeout is a channel ↗
- In the books: Effective Concurrency in Go, Burak Serdar — ch. 7, 'Timers and Tickers'
- In the books: Combine: Asynchronous Programming with Swift, Shai Mishali, Florent Pillet, Marin Todorov, Scott Gardner — ch. 11, 'Timers'
- In the books: Pro Asynchronous Programming with .NET, Richard Blewett, Andrew Clymer — ch. 6, 'Asynchronous UI' → 'UI Timers'
- In the books: JavaScript Concurrency, Adam Boduch — ch. 2, 'The JavaScript Execution Model' → 'Creating tasks using timers'
- In the books: Hands-On RTOS with Microcontrollers, Brian Amos — ch. 8, 'Protecting Data and Synchronizing Tasks' → 'Using software timers'
- In the books: C# 10 in a Nutshell, Joseph Albahari — ch. 21, 'Advanced Threading' → 'Timers'