Skip to content

Instantly share code, notes, and snippets.

@kinnison
Last active April 10, 2018 12:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kinnison/7193527bc2730ff6f311b033de7fe73f to your computer and use it in GitHub Desktop.
Save kinnison/7193527bc2730ff6f311b033de7fe73f to your computer and use it in GitHub Desktop.
Iterator stream snippet
trace!("Preparing an Interval to run the requests");
let always_defs = futures::stream::iter_ok(raw_defs.iter().cycle());
let every_100ms = Interval::new(Instant::now(), Duration::from_millis(100));
let zipped = every_100ms.zip(always_defs);
tokio::spawn(zipped.map_err(|_| ()).for_each(move |(_, def)| {
let req = def.request();
let dest = req.sendto();
let packet = req.packet().to_vec();
let targ = sender.clone();
tokio::spawn(futures::future::lazy(move || {
targ.send((dest, packet)).wait().map(|_| ()).map_err(|_| ())
}))
}));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment