OxL Reference

fn throttle

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

Example:

oxl✓ checked in 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}")
}
Output
[1]
pub(api) fn throttle<T, E>(s: stream<T, E>, d: Duration) -> stream<T, E>  time

Complexity. O(1) per element.

Since. 1.0.0-beta

Parameters

NameType
sstream<T, E>
dDuration

Returns

stream<T, E>

Effects

time

Defined in: std/stream/stream.oxl:451

See also