Crate fluxion_stream_time

Crate fluxion_stream_time 

Source
Expand description

Time-based operators for streams with runtime-agnostic timer abstraction.

This crate provides time-based operators for delaying, debouncing, throttling, sampling, and timeout handling of stream emissions. Operators work with any async runtime through the Timer trait abstraction.

§Overview

  • Timer trait - Runtime-agnostic timer abstraction
  • InstantTimestamped<T, TM> - Wraps a value with a Timer’s Instant timestamp
  • DelayExt - Extension trait for .delay(duration, timer)
  • DebounceExt - Extension trait for .debounce(duration, timer)
  • ThrottleExt - Extension trait for .throttle(duration, timer)
  • SampleExt - Extension trait for .sample(duration, timer)
  • TimeoutExt - Extension trait for .timeout(duration, timer)

§Runtime Support

Enable runtime-specific features in your Cargo.toml:

  • runtime-tokio (default) - Tokio runtime support with TokioTimer
  • runtime-smol - smol runtime support with SmolTimer
  • runtime-wasm - WebAssembly support with WasmTimer
  • runtime-embassy - Embassy (embedded) runtime support with EmbassyTimerImpl (no_std)
  • runtime-async-std - async-std runtime ⚠️ DEPRECATED (unmaintained, RUSTSEC-2025-0052)

⚠️ Note: async-std is discontinued. Use tokio or smol for new projects.

§Example

use fluxion_stream_time::{DebounceExt, DelayExt, TokioTimestamped};
use fluxion_runtime::impls::tokio::TokioTimer;
use fluxion_runtime::timer::Timer;
use fluxion_core::StreamItem;
use futures::stream::StreamExt;
use std::time::Duration;
use futures::channel::mpsc;

let (tx, rx) = mpsc::unbounded::<TokioTimestamped<i32>>();
let timer = TokioTimer;

// Delay all emissions by 100ms (convenience method)
let delayed = rx
    .map(StreamItem::Value)
    .delay(Duration::from_millis(100));

tx.unbounded_send(TokioTimestamped::new(42, timer.now())).unwrap();
tx.unbounded_send(TokioTimestamped::new(100, timer.now())).unwrap();

// Or debounce with convenience method (no timer parameter needed)
let debounced = rx
    .map(StreamItem::Value)
    .debounce(Duration::from_millis(100));

Structs§

InstantTimestamped
A timestamped value using a Timer’s Instant type for monotonic time operations.
TokioRuntime

Traits§

DebounceExt
Extension trait providing the debounce operator for streams.
DelayExt
Extension trait providing the delay operator for streams.
SampleExt
Extension trait providing the sample operator for streams.
ThrottleExt
Extension trait providing the throttle operator for streams.
TimeoutExt
Extension trait providing the timeout operator for streams.

Type Aliases§

DefaultRuntime
TokioTimestamped