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:
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}")
}Вывод
false
pub(api) fn every<effect F>(d: Dur, missed: Missed = .Skip, body: fn() F) time, FПотокобезопасность. runs in the calling task until it is cancelled.
С версии. 1.0.0-beta
Параметры
| Имя | Тип |
|---|---|
d | Dur |
missed | Missed = .Skip |
body | fn() F |
Ошибки
panics when the period is not positive.
Эффекты
не объявлены (чистая, пока тело не говорит иное)
Определено в: std/time/time.oxl:2547