pub struct TaskGroup {
inner: Arc<Inner>,
}Expand description
TaskGroup A group that contains spawned tasks.
§Example
use std::sync::Arc;
use karyon_core::async_util::{TaskGroup, sleep};
async {
let group = TaskGroup::new();
group.spawn(sleep(std::time::Duration::MAX));
group.cancel().await;
};
Fields§
§inner: Arc<Inner>Implementations§
Source§impl TaskGroup
impl TaskGroup
Sourcepub fn new() -> Self
pub fn new() -> Self
Creates a new TaskGroup without providing an executor
This will spawn a task onto a global executor (single-threaded by default).
Sourcepub fn with_executor(executor: Executor) -> Self
pub fn with_executor(executor: Executor) -> Self
Creates a new TaskGroup by providing an executor
fn with_inner(executor: Executor) -> Self
Sourcepub fn spawn<T, Fut>(&self, fut: Fut) -> usize
pub fn spawn<T, Fut>(&self, fut: Fut) -> usize
Spawns a new task and ignores its result.
Returns the task’s TaskID. The task removes itself from the
group when it finishes, so the group does not grow without bound.
Sourcepub fn spawn_then<T, Fut, CallbackF, CallbackFut>(
&self,
fut: Fut,
callback: CallbackF,
) -> usize
pub fn spawn_then<T, Fut, CallbackF, CallbackFut>( &self, fut: Fut, callback: CallbackF, ) -> usize
Spawns a new task and calls the callback after it has completed
or been canceled. The callback will have the TaskResult as a
parameter, indicating whether the task completed or was canceled.
Returns the task’s TaskID.
Sourcepub fn remove(&self, id: usize) -> Option<TaskHandler>
pub fn remove(&self, id: usize) -> Option<TaskHandler>
Removes a task by id, returning its handler if still present. The caller takes ownership and may cancel it.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for TaskGroup
impl !RefUnwindSafe for TaskGroup
impl Send for TaskGroup
impl Sync for TaskGroup
impl Unpin for TaskGroup
impl UnsafeUnpin for TaskGroup
impl !UnwindSafe for TaskGroup
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