Last active
April 10, 2018 12:23
-
-
Save kinnison/7193527bc2730ff6f311b033de7fe73f to your computer and use it in GitHub Desktop.
Iterator stream snippet
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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