OxL Reference

fn every

Runs body every d until the task is cancelled (§17.4). Ticks are counted from the start (no drift). When body takes longer than d, .Skip (default) drops the ticks it missed and .CatchUp runs them back to back.

Example:

oxl✓ checked in CI
use std.time { every }

fn main() io, time {
  let (tx, rx) = chan<i64>(cap: 64)
  scope {
    let h = spawn (() => every(10ms) {
      let _ = tx.send(1)
    })
    sleep(75ms)
    h.cancel()
  }
  var ticks = 0
  while rx.tryRecv() != none { ticks += 1 }
  print("{ticks >= 3}")
}
Output
false
pub(api) fn every<effect F>(d: Dur, missed: Missed = .Skip, body: fn() F) time, F

Thread safety. runs in the calling task until it is cancelled.

Since. 1.0.0-beta

Parameters

NameType
dDur
missedMissed = .Skip
bodyfn() F

Errors

panics when the period is not positive.

Effects

none declared (pure unless the body says otherwise)

Defined in: std/time/time.oxl:2547

See also