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>

source

pub fn new( creator: impl FnOnce(Sender<Status<M>>) -> ImmediateValuePromise<T>, buffer: usize ) -> Self

create a new Progress tracked immediate value promise.

source

pub fn status_history(&self) -> &[Status<M>]

Slice of all recorded Status changes

source

pub fn last_status(&self) -> Option<&Status<M>>

Get the last Status if there is any

source

pub fn finished(&self) -> bool

Is our future already finished?

source

pub fn poll_state(&mut self) -> &ImmediateValueState<T>

Poll the state and process the messages

source

pub fn get_progress(&self) -> Progress

Get the current progress

Trait Implementations§

source§

impl<T: Send + 'static, M> DirectCacheAccess<T> for ProgressTrackedImValProm<T, M>

source§

fn get_value_mut(&mut self) -> Option<&mut T>

returns mutable reference to the cache if applicable
source§

fn get_value(&self) -> Option<&T>

returns a reference to the cache if applicable
source§

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> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere 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 Twhere 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, U> TryFrom<U> for Twhere 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 Twhere 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.