Function timely::execute::example

source ·
pub fn example<T, F>(func: F) -> T
where T: Send + 'static, F: FnOnce(&mut Child<'_, Worker<Thread>, u64>) -> T + Send + Sync + 'static,
Expand description

Executes a single-threaded timely dataflow computation.

The example method takes a closure on a Scope which it executes to initialize and run a timely dataflow computation on a single thread. This method is intended for use in examples, rather than programs that may need to run across multiple workers.

The example method returns whatever the single worker returns from its closure. This is often nothing, but the worker can return something about the data it saw in order to test computations.

The method aggressively unwraps returned Result<_> types.


The simplest example creates a stream of data and inspects it.

use timely::dataflow::operators::{ToStream, Inspect};

timely::example(|scope| {
           .inspect(|x| println!("seen: {:?}", x));

This next example captures the data and displays them once the computation is complete.

More precisely, the example captures a stream of events (receiving batches of data, updates to input capabilities) and displays these events.

use timely::dataflow::operators::{ToStream, Inspect, Capture};
use timely::dataflow::operators::capture::Extract;

let data = timely::example(|scope| {
           .inspect(|x| println!("seen: {:?}", x))

// the extracted data should have data (0..10) at timestamp 0.
assert_eq!(data.extract()[0].1, (0..10).collect::<Vec<_>>());