This module implements a timer dispatcher and a ticker dispatcher. A timer delays an operation after some milliseconds. A ticker delays an operation to the next iteration.
- newTimer() -> SetTimeout() -> clearTimeout()
- -> ...
setTimeout() -> clearTimeout()
Types
TimerEntity = object delay: int finishAt: float callback: proc () {.
closure, gcsafe.} joined: bool- Timer object. Source Edit
Timer = distinct ref DoublyLinkedNodeObj[TimerEntity]
- Timer object. Source Edit
TimerQueue = ref object handle: uv.Timer entities: DoublyLinkedList[TimerEntity] delay: int length: int running: bool closed: bool
- Timer queue for one delay. Source Edit
TimerDispatcher = ref object timers: Table[int, TimerQueue]
- Source Edit
TickerDispatcher = ref object handle: Idle running: bool callbacks: seq[proc ()]
- Source Edit
Procs
proc newTimerDispatcher(): TimerDispatcher {.
raises: [], tags: [].}- Creates a new dispatcher for timeout tasks. Source Edit
proc getGTimerDispatcher(): TimerDispatcher {.
raises: [], tags: [].}- Returns the global dispatcher of timeout tasks. Source Edit
proc newTimer(): Timer {.
raises: [], tags: [].}- Creates a new timer. Source Edit
proc setTimeout(T: Timer; delay: int; cb: proc () {.
closure, gcsafe.}) {.raises: [KeyError, Exception], tags: [TimeEffect, RootEffect].}- Sets a new timeout task. cb will be executed after delay milliseconds. Source Edit
proc setTimeout(delay: int; cb: proc () {.
closure, gcsafe.}): Timer {.discardable, raises: [KeyError, Exception], tags: [TimeEffect, RootEffect].}- Source Edit
proc clearTimeout(T: Timer) {.
raises: [KeyError], tags: [].}- Clears T from timeout queue before excution. Source Edit
proc newTickerDispatcher(): TickerDispatcher {.
raises: [], tags: [].}- Creates new dispatcher for tickers. Source Edit
proc getGTickerDispatcher(): TickerDispatcher {.
raises: [], tags: [].}- Source Edit
proc callNext(cb: proc ()) {.
gcsafe, raises: [Exception], tags: [RootEffect].}- cb will be deferred to the next iteration to excute. Source Edit