pub struct ProgressTracker { /* private fields */ }Expand description
A helper for sending progress updates for a long-running operation.
This wraps a NotificationSender and an optional progress token, making it
easy to report progress without checking if the token is present each time.
Implementations§
Source§impl ProgressTracker
impl ProgressTracker
Sourcepub fn new(notifier: NotificationSender, token: Option<ProgressToken>) -> Self
pub fn new(notifier: NotificationSender, token: Option<ProgressToken>) -> Self
Create a new progress tracker.
If token is None, all progress updates will be no-ops.
Sourcepub fn from_meta(notifier: NotificationSender, meta: Option<&Value>) -> Self
pub fn from_meta(notifier: NotificationSender, meta: Option<&Value>) -> Self
Create a tracker from a request’s _meta.progressToken.
Extracts the progress token from the _meta field of a request params object.
Sourcepub async fn update(&self, progress: f64, total: f64, message: Option<String>)
pub async fn update(&self, progress: f64, total: f64, message: Option<String>)
Send a progress update.
progress: Current progress valuetotal: Total value (progress/total gives percentage)message: Optional status message
Returns silently if no progress token was provided.
Sourcepub async fn update_percent(&self, percent: f64, message: Option<String>)
pub async fn update_percent(&self, percent: f64, message: Option<String>)
Send a progress update with just a percentage (0.0 to 1.0).
Sourcepub async fn update_with_message(
&self,
progress: f64,
total: f64,
message: impl Into<String>,
)
pub async fn update_with_message( &self, progress: f64, total: f64, message: impl Into<String>, )
Send a progress update with a message.
Sourcepub async fn complete(&self, message: impl Into<String>)
pub async fn complete(&self, message: impl Into<String>)
Mark the operation as complete with a final message.
Sourcepub fn is_tracking(&self) -> bool
pub fn is_tracking(&self) -> bool
Check if progress tracking is enabled (token was provided).
Auto Trait Implementations§
impl Freeze for ProgressTracker
impl RefUnwindSafe for ProgressTracker
impl Send for ProgressTracker
impl Sync for ProgressTracker
impl Unpin for ProgressTracker
impl UnsafeUnpin for ProgressTracker
impl UnwindSafe for ProgressTracker
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