Struct Progress

Source
pub struct Progress<State>
where State: 'static + Clone + Send + Sync + Eq + Debug,
{ /* private fields */ }
Expand description

A progress tracker.

You can call set_state and it will notify observers of the new state.

To wait for a specific state, you can call wait or once.

Progress is Clone and it’s methods only require a shared reference for convenience.

Implementations§

Source§

impl<State> Progress<State>
where State: 'static + Clone + Send + Sync + Eq + Debug,

Source

pub fn new(state: State) -> Self

Create a Progress with an initial state.

Source

pub async fn set_state(&self, new_state: State)

Set a new state. Observers will be notified.

Source

pub fn current(&self) -> State

Check the current state.

Source

pub fn wait(&self, state: State) -> Events<State>

Create an event stream that will only fire for the given state. This is a stream and if you call set_state several times with the given state, this will yield several events.

Note that events fired before you call this will not be delivered to the stream. It’s recommended to set up all observers first and then start doing work that can call set_state.

Note that this method uses block_on to lock a mutex on the pharos object, so it might block the thread. All operations on Progress are really short, so this shouldn’t be a problem as long as you haven’t set up an observer by calling Progress::observe with a bounded channel with a low queue size. If the sending of an event (in set_state) returns pending, and this method is called, that will deadlock.

Source

pub fn once(&self, state: State) -> impl Future + Send

Create a future that will resolve when a certain state is next triggered.

Note that events fired before you call this will not be delivered to the stream. It’s recommended to set up all observers first and then start doing work that can call set_state.

Note that this method uses block_on to lock a mutex on the pharos object, so it might block the thread. All operations on Progress are really short, so this shouldn’t be a problem as long as you haven’t set up an observer by calling Progress::observe with a bounded channel with a low queue size. If the sending of an event (in set_state) returns pending, and this method is called, that will deadlock.

Trait Implementations§

Source§

impl<State> Clone for Progress<State>
where State: 'static + Clone + Send + Sync + Eq + Debug + Clone,

Source§

fn clone(&self) -> Progress<State>

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<State> Debug for Progress<State>
where State: 'static + Clone + Send + Sync + Eq + Debug,

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<State> Observable<State> for Progress<State>
where State: 'static + Clone + Send + Sync + Eq + Debug,

Source§

fn observe( &mut self, options: ObserveConfig<State>, ) -> Observe<'_, State, Self::Error>

Avoid configuring pharos with a bounded channel of a low queue size. It is possible to create a deadlock if the send in Progress::set_state returns pending and you call another method on Progress that uses block_on, notably Progress::current.

Source§

type Error = PharErr

The error type that is returned if observing is not possible. Read more

Auto Trait Implementations§

§

impl<State> Freeze for Progress<State>

§

impl<State> !RefUnwindSafe for Progress<State>

§

impl<State> Send for Progress<State>

§

impl<State> Sync for Progress<State>

§

impl<State> Unpin for Progress<State>

§

impl<State> !UnwindSafe for Progress<State>

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

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

Source§

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>,

Source§

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.