[−][src]Struct async_progress::Progress
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.
Methods
impl<State> Progress<State> where
State: 'static + Clone + Send + Sync + Eq + Debug,
[src]
State: 'static + Clone + Send + Sync + Eq + Debug,
pub fn new(state: State) -> Self
[src]
Create a Progress with an initial state.
pub async fn set_state<'_>(&'_ self, new_state: State)
[src]
Set a new state. Observers will be notified.
pub fn current(&self) -> State
[src]
Check the current state.
pub fn wait(&self, state: State) -> Events<State>
[src]
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.
pub fn once(&self, state: State) -> impl Future + Send
[src]
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
impl<State: Clone> Clone for Progress<State> where
State: 'static + Clone + Send + Sync + Eq + Debug,
[src]
State: 'static + Clone + Send + Sync + Eq + Debug,
impl<State> Debug for Progress<State> where
State: 'static + Clone + Send + Sync + Eq + Debug,
[src]
State: 'static + Clone + Send + Sync + Eq + Debug,
impl<State> Observable<State> for Progress<State> where
State: 'static + Clone + Send + Sync + Eq + Debug,
[src]
State: 'static + Clone + Send + Sync + Eq + Debug,
type Error = Error
The error type that is returned if observing is not possible. Read more
fn observe(
&mut self,
options: ObserveConfig<State>
) -> Result<Events<State>, Self::Error>
[src]
&mut self,
options: ObserveConfig<State>
) -> Result<Events<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
.
Auto Trait Implementations
impl<State> Send for Progress<State>
impl<State> Unpin for Progress<State>
impl<State> Sync for Progress<State>
impl<State> !RefUnwindSafe for Progress<State>
impl<State> !UnwindSafe for Progress<State>
Blanket Implementations
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
fn to_owned(&self) -> T
[src]
fn clone_into(&self, target: &mut T)
[src]
impl<T> From<T> for T
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,