gleamtea/timer

A bubble: a countdown timer. Like the spinner, it keeps itself running by re-scheduling its own tick; forward every message to update.

Types

An opaque countdown-timer value.

pub type Timer

Values

pub fn new(
  timeout_ms timeout_ms: Int,
  interval_ms interval_ms: Int,
) -> Timer

A timer that counts down timeout_ms milliseconds, ticking every interval_ms. It starts paused — call start or toggle to begin.

pub fn remaining_ms(timer: Timer) -> Int

The remaining time in milliseconds.

pub fn running(timer: Timer) -> Bool

Is the timer currently counting down?

pub fn start(timer: Timer) -> gleamtea.Cmd(msg)

Start (or resume) counting down; returns the command that schedules the first tick.

pub fn timed_out(timer: Timer) -> Bool

Has the timer reached zero?

pub fn toggle(timer: Timer) -> #(Timer, gleamtea.Cmd(msg))

Pause/resume. Returns the (possibly re-armed) command.

pub fn update(
  msg: msg,
  timer: Timer,
) -> #(Timer, gleamtea.Cmd(msg))

Advance on the timer’s own tick; ignore other messages.

pub fn view(timer: Timer) -> String

Render the remaining time as MM:SS.

Search Document