OxL Справочник OxL
РусскийEnglish

fn throttle

Keeps the first element of every interval of d, drops the rest.

Example:

oxl✓ проверяется в CI
use std.stream { throttle }

fn nums() -> stream<i32> {
  for i in 1..=3 { yield i }
}

fn main() io, time {
  var out: List<i32> = []
  // all three arrive within the interval: only the first passes
  for await x in nums() |> throttle(1h) {
    out.push(x)
  }
  print("{out}")
}
Вывод
[1]
pub(api) fn throttle<T, E>(s: stream<T, E>, d: Duration) -> stream<T, E>  time

Сложность. O(1) per element.

С версии. 1.0.0-beta

Параметры

ИмяТип
sstream<T, E>
dDuration

Возвращает

stream<T, E>

Эффекты

time

Определено в: std/stream/stream.oxl:451

См. также