pub struct ScopeHandle { /* private fields */ }
Expand description
A handle to a scope, which may be used to spawn tasks.
§Ownership and cycles
Tasks running on a Scope
may hold a ScopeHandle
to that scope. This does
not create an ownership cycle because the task will drop the ScopeHandle
once it completes or is cancelled.
Naturally, scopes containing tasks that never complete and that are never
cancelled will never be freed. Holding a ScopeHandle
does not contribute to
this problem.
Implementations§
Source§impl ScopeHandle
impl ScopeHandle
Sourcepub fn spawn(
&self,
future: impl Future<Output = ()> + Send + 'static,
) -> JoinHandle<()> ⓘ
pub fn spawn( &self, future: impl Future<Output = ()> + Send + 'static, ) -> JoinHandle<()> ⓘ
Spawn a new task on the scope.
Sourcepub fn spawn_local(
&self,
future: impl Future<Output = ()> + 'static,
) -> JoinHandle<()> ⓘ
pub fn spawn_local( &self, future: impl Future<Output = ()> + 'static, ) -> JoinHandle<()> ⓘ
Spawn a new task on the scope of a thread local executor.
NOTE: This is not supported with a SendExecutor
and will cause a runtime panic. Use ScopeHandle::spawn
instead.
Sourcepub fn compute<T: Send + 'static>(
&self,
future: impl Future<Output = T> + Send + 'static,
) -> Task<T> ⓘ
pub fn compute<T: Send + 'static>( &self, future: impl Future<Output = T> + Send + 'static, ) -> Task<T> ⓘ
Like spawn
, but for tasks that return a result.
NOTE: Unlike spawn
, when tasks are dropped, the future will be
cancelled.
Sourcepub fn compute_local<T: 'static>(
&self,
future: impl Future<Output = T> + 'static,
) -> Task<T> ⓘ
pub fn compute_local<T: 'static>( &self, future: impl Future<Output = T> + 'static, ) -> Task<T> ⓘ
Like spawn
, but for tasks that return a result.
NOTE: Unlike spawn
, when tasks are dropped, the future will be
cancelled.
NOTE: This is not supported with a SendExecutor
and will cause a runtime panic. Use ScopeHandle::spawn
instead.
Sourcepub fn close(&self)
pub fn close(&self)
Stop the scope from accepting new tasks.
Note that unlike Scope::close
, this does not return a future that
waits for all tasks to complete. This could lead to resource leaks
because it is not uncommon to access a TaskGroup from a task running on
the scope itself. If such a task were to await a future returned by this
method it would suspend forever waiting for itself to complete.
Sourcepub fn cancel(self) -> impl Future<Output = ()>
pub fn cancel(self) -> impl Future<Output = ()>
Cancel all the scope’s tasks.
Note that if this is called from within a task running on the scope, the task will not resume from the next await point.
Sourcepub async fn on_no_tasks(&self)
pub async fn on_no_tasks(&self)
Wait for there to be no tasks. This is racy: as soon as this returns it is possible for another task to have been spawned on this scope.
Trait Implementations§
Source§impl Borrow<ScopeHandle> for Scope
impl Borrow<ScopeHandle> for Scope
Source§fn borrow(&self) -> &ScopeHandle
fn borrow(&self) -> &ScopeHandle
Source§impl Clone for ScopeHandle
impl Clone for ScopeHandle
Source§fn clone(&self) -> ScopeHandle
fn clone(&self) -> ScopeHandle
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moreAuto Trait Implementations§
impl Freeze for ScopeHandle
impl !RefUnwindSafe for ScopeHandle
impl Send for ScopeHandle
impl Sync for ScopeHandle
impl Unpin for ScopeHandle
impl !UnwindSafe for ScopeHandle
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)