Struct broot::task_sync::Dam [−][src]
pub struct Dam { /* fields omitted */ }
Expand description
The dam controls the flow of events.
A dam is used in broot to manage long computations and,
when the user presses a key, either tell the computation
to stop (the computation function checking has_event
)
or drop the computation.
Implementations
provide an observer which can be used for periodic check a task can be used. The observer can safely be moved to another thread but Be careful not to use it after the event listener started again. In any case using try_compute should be prefered for immediate return to the ui thread.
pub fn try_compute<V: Send + 'static, F: Send + 'static + FnOnce() -> ComputationResult<V>>(
&mut self,
f: F
) -> ComputationResult<V>
pub fn try_compute<V: Send + 'static, F: Send + 'static + FnOnce() -> ComputationResult<V>>(
&mut self,
f: F
) -> ComputationResult<V>
launch the computation on a new thread and return when it finishes or when a new event appears on the channel. Note that the task itself isn’t interrupted so that this should not be used when many tasks are expected to be launched (or it would result in many working threads uselessly working in the background) : use dam.has_event from inside the task whenever possible.
pub fn select<V>(
&mut self,
comp_receiver: Receiver<ComputationResult<V>>
) -> ComputationResult<V>
block until next event (including the one which may have been pushed back into the dam). no event means the source is dead (i.e. we must quit broot) There’s no event kept in dam after this call.