Skip to content

Instantly share code, notes, and snippets.

View gardell's full-sized avatar

Johan Gardell gardell

  • Amazon
  • Stockholm
View GitHub Profile
@gardell
gardell / lowpassfilter.rs
Last active February 10, 2020 18:00
Rust Stream lowpass filter
/// Any time a stream resolves a value, a timer is started.
/// When the timer finishes, the last value that the stream has resolved during the timer window
/// is returned. Any intermediate value is dropped.
pub fn low_pass_filter<'a, T: 'a>(
stream: futures_util::stream::LocalBoxStream<'a, T>,
delay_: std::time::Duration
) -> impl futures_util::stream::Stream<Item = Result<T, Error>> + 'a {
use futures_util::{future::{Either, LocalBoxFuture, select}, stream::{Stream, StreamExt, StreamFuture, try_unfold}};
use std::{future::Future, marker::Unpin};