Skip to content

Instantly share code, notes, and snippets.

@milibopp
Last active August 11, 2017 10:18
Show Gist options
  • Save milibopp/7c7959ac58e2d3575af9487d75ec2f22 to your computer and use it in GitHub Desktop.
Save milibopp/7c7959ac58e2d3575af9487d75ec2f22 to your computer and use it in GitHub Desktop.
While-loop in timely dataflow
extern crate timely;
use timely::*;
use timely::dataflow::operators::*;
use std::iter::once;
fn main() {
execute_from_args(std::env::args(), |worker| {
let index = worker.index();
worker.dataflow(|scope| {
let (helper, state) = scope.loop_variable(std::u64::MAX, 1);
let state = once(0).to_stream(scope)
.concat(&state)
.map(|i| i + 1)
.filter(|i| *i < 5);
state
.inspect(move |i| println!("{}: state {}", index, i));
state
.connect_loop(helper);
});
}).unwrap();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment