Struct broot::task_sync::Dam

source ·
pub struct Dam { /* private fields */ }
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§

source§

impl Dam

source

pub fn from(receiver: Receiver<TimedEvent>) -> Self

source

pub fn unlimited() -> Self

source

pub fn observer(&self) -> DamObserver

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 preferred for immediate return to the ui thread.

source

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.

source

pub fn select<V>( &mut self, comp_receiver: Receiver<ComputationResult<V>> ) -> ComputationResult<V>

source

pub fn has_event(&self) -> bool

non blocking

source

pub fn clear(&mut self) -> usize

drop all events, returns the count of removed events

source

pub fn next_event(&mut self) -> Option<TimedEvent>

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.

source

pub fn next<T>( &mut self, other: &Receiver<T> ) -> Either<Option<TimedEvent>, Option<T>>

Auto Trait Implementations§

§

impl RefUnwindSafe for Dam

§

impl Send for Dam

§

impl Sync for Dam

§

impl Unpin for Dam

§

impl UnwindSafe for Dam

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

§

impl<T> Pointable for T

§

const ALIGN: usize = _

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.