pub struct ProgressTrackedImValProm<T: Send, M> { /* private fields */ }
Expand description
A progress and status enabling wrapper for ImmediateValuePromise
This struct allows to use the Progress
type and any kind of status message
You can use this to set a computation progress and optionally attach any kind of status message.
Assume your action runs for an extended period of time and you want to inform the user about the state:
use std::borrow::Cow;
use std::time::Duration;
use lazy_async_promise::{ImmediateValueState, ImmediateValuePromise, Progress, ProgressTrackedImValProm, StringStatus};
let mut oneshot_progress = ProgressTrackedImValProm::new( |s| { ImmediateValuePromise::new(
async move {
//send some initial status
s.send(StringStatus::new(
Progress::from_percent(0.0),
"Initializing".into(),
)).await.unwrap();
// do some long running operation
for i in 0..100 {
tokio::time::sleep(Duration::from_millis(50)).await;
s.send(StringStatus::new(
Progress::from_percent(i as f64),
Cow::Borrowed("In progress"))).await.unwrap();
}
Ok(34)
})}, 2000);
assert!(matches!(
oneshot_progress.poll_state(),
ImmediateValueState::Updating));
//waiting and polling will yield "In progress" now :)
Implementations§
source§impl<T: Send + 'static, M> ProgressTrackedImValProm<T, M>
impl<T: Send + 'static, M> ProgressTrackedImValProm<T, M>
sourcepub fn new(
creator: impl FnOnce(Sender<Status<M>>) -> ImmediateValuePromise<T>,
buffer: usize
) -> Self
pub fn new( creator: impl FnOnce(Sender<Status<M>>) -> ImmediateValuePromise<T>, buffer: usize ) -> Self
create a new Progress tracked immediate value promise.
sourcepub fn status_history(&self) -> &[Status<M>]
pub fn status_history(&self) -> &[Status<M>]
Slice of all recorded Status
changes
sourcepub fn last_status(&self) -> Option<&Status<M>>
pub fn last_status(&self) -> Option<&Status<M>>
Get the last Status
if there is any
sourcepub fn poll_state(&mut self) -> &ImmediateValueState<T>
pub fn poll_state(&mut self) -> &ImmediateValueState<T>
Poll the state and process the messages
sourcepub fn get_progress(&self) -> Progress
pub fn get_progress(&self) -> Progress
Get the current progress
Trait Implementations§
source§impl<T: Send + 'static, M> DirectCacheAccess<T> for ProgressTrackedImValProm<T, M>
impl<T: Send + 'static, M> DirectCacheAccess<T> for ProgressTrackedImValProm<T, M>
source§fn get_value_mut(&mut self) -> Option<&mut T>
fn get_value_mut(&mut self) -> Option<&mut T>
returns mutable reference to the cache if applicable
source§fn take_value(&mut self) -> Option<T>
fn take_value(&mut self) -> Option<T>
takes the value and leaves the promise in a valid state indicating its emptiness
Auto Trait Implementations§
impl<T, M> !RefUnwindSafe for ProgressTrackedImValProm<T, M>
impl<T, M> Send for ProgressTrackedImValProm<T, M>where M: Send,
impl<T, M> !Sync for ProgressTrackedImValProm<T, M>
impl<T, M> Unpin for ProgressTrackedImValProm<T, M>where M: Unpin, T: Unpin,
impl<T, M> !UnwindSafe for ProgressTrackedImValProm<T, M>
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more