Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions timely/src/worker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -392,6 +392,11 @@ impl<A: Allocate> Worker<A> {

/// Calls `self.step()` as long as `func` evaluates to true.
///
/// This method will continually execute even if there is not work
/// for the worker to perform. Consider using the similar method
/// `Self::step_or_park_while(duration)` to allow the worker to yield
/// control if that is appropriate.
///
/// # Examples
///
/// ```
Expand All @@ -414,6 +419,35 @@ impl<A: Allocate> Worker<A> {
while func() { self.step(); }
}

/// Calls `self.step_or_park(duration)` as long as `func` evaluates to true.
///
/// This method may yield whenever there is no work to perform, as performed
/// by `Self::step_or_park()`. Please consult the documentation for further
/// information about that method and its behavior. In particular, the method
/// can park the worker indefinitely, if no new work re-awakens the worker.
///
/// # Examples
///
/// ```
/// timely::execute_from_args(::std::env::args(), |worker| {
///
/// use timely::dataflow::operators::{ToStream, Inspect, Probe};
///
/// let probe =
/// worker.dataflow::<usize,_,_>(|scope| {
/// (0 .. 10)
/// .to_stream(scope)
/// .inspect(|x| println!("{:?}", x))
/// .probe()
/// });
///
/// worker.step_or_park_while(None, || probe.less_than(&0));
/// });
/// ```
pub fn step_or_park_while<F: FnMut()->bool>(&mut self, duration: Option<Duration>, mut func: F) {
while func() { self.step_or_park(duration); }
}

/// The index of the worker out of its peers.
///
/// # Examples
Expand Down