pub struct TaskHandle { /* private fields */ }Expand description
A unified handle for scheduled tasks that serves dual purposes.
TaskHandle implements both Subscription and Future, providing:
- Cancellation: Call
unsubscribe()to stop the task - Completion tracking: Await the handle to wait for task completion
- Status checking: Use
is_closed()to check if task is done or cancelled
§Thread Safety
TaskHandle is Clone + Send + Sync, allowing it to be shared across threads
and async contexts safely.
§Example
use std::sync::{Arc, Mutex};
use rxrust::{
scheduler::{LocalScheduler, Scheduler, Task, TaskState},
subscription::Subscription,
};
let scheduler = LocalScheduler;
let data = Arc::new(Mutex::new(0));
let task = Task::new(data, |_| TaskState::Finished);
let handle = scheduler.schedule(task, None);
// Option 1: Cancel the task
handle.clone().unsubscribe();
// Option 2: Wait for completion
// In async context: handle.await;
// Option 3: Check status
if handle.is_closed() {
println!("Task finished or was cancelled");
}Implementations§
Source§impl TaskHandle
impl TaskHandle
Sourcepub fn finished() -> Self
pub fn finished() -> Self
Create a handle for a task that has already completed.
This is useful for:
- Synchronous operations that complete immediately
- Error cases where no actual scheduling is needed
- Testing scenarios
The returned handle will immediately return Poll::Ready(()) when polled
and is_closed() will return true.
Trait Implementations§
Source§impl Clone for TaskHandle
impl Clone for TaskHandle
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Future for TaskHandle
impl Future for TaskHandle
Source§impl Subscription for TaskHandle
impl Subscription for TaskHandle
Source§fn unsubscribe(self)
fn unsubscribe(self)
Cancel the subscription (terminal operation, consumes self)
Source§fn unsubscribe_when_dropped(self) -> SubscriptionGuard<Self>where
Self: Sized,
fn unsubscribe_when_dropped(self) -> SubscriptionGuard<Self>where
Self: Sized,
Activates “RAII” behavior for this subscription. That means
unsubscribe() will be called automatically as soon as the returned
value goes out of scope. Read moreAuto Trait Implementations§
impl Freeze for TaskHandle
impl RefUnwindSafe for TaskHandle
impl Send for TaskHandle
impl Sync for TaskHandle
impl Unpin for TaskHandle
impl UnwindSafe for TaskHandle
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
Source§impl<T> BoxedSubscriptionInner for Twhere
T: Subscription,
impl<T> BoxedSubscriptionInner for Twhere
T: Subscription,
fn boxed_unsubscribe(self: Box<T>)
fn boxed_is_closed(&self) -> bool
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoBoxedSubscription<BoxedSubscription> for Twhere
T: Subscription + 'static,
impl<T> IntoBoxedSubscription<BoxedSubscription> for Twhere
T: Subscription + 'static,
Source§fn into_boxed(self) -> BoxedSubscription
fn into_boxed(self) -> BoxedSubscription
Convert this subscription into a boxed subscription.
Source§impl<T> IntoBoxedSubscription<BoxedSubscriptionSend> for Twhere
T: Subscription + Send + 'static,
impl<T> IntoBoxedSubscription<BoxedSubscriptionSend> for Twhere
T: Subscription + Send + 'static,
Source§fn into_boxed(self) -> BoxedSubscriptionSend
fn into_boxed(self) -> BoxedSubscriptionSend
Convert this subscription into a boxed subscription.
Source§impl<F> IntoFuture for Fwhere
F: Future,
impl<F> IntoFuture for Fwhere
F: Future,
Source§type IntoFuture = F
type IntoFuture = F
Which kind of future are we turning this into?
Source§fn into_future(self) -> <F as IntoFuture>::IntoFuture
fn into_future(self) -> <F as IntoFuture>::IntoFuture
Creates a future from a value. Read more
Source§impl<F, Sch> Schedulable<Sch> for F
impl<F, Sch> Schedulable<Sch> for F
Source§fn into_future(self, _scheduler: &Sch) -> <F as Schedulable<Sch>>::Future
fn into_future(self, _scheduler: &Sch) -> <F as Schedulable<Sch>>::Future
Convert this item into a future using the given scheduler’s capabilities