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
Timertrait - Runtime-agnostic timer abstractionInstantTimestamped<T, TM>- Wraps a value with a Timer’s Instant timestampDelayExt- 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 withTokioTimerruntime-smol- smol runtime support withSmolTimerruntime-wasm- WebAssembly support withWasmTimerruntime-embassy- Embassy (embedded) runtime support withEmbassyTimerImpl(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§
- Instant
Timestamped - A timestamped value using a Timer’s Instant type for monotonic time operations.
- Tokio
Runtime
Traits§
- Debounce
Ext - Extension trait providing the
debounceoperator for streams. - Delay
Ext - Extension trait providing the
delayoperator for streams. - Sample
Ext - Extension trait providing the
sampleoperator for streams. - Throttle
Ext - Extension trait providing the
throttleoperator for streams. - Timeout
Ext - Extension trait providing the
timeoutoperator for streams.