Struct zksync_concurrency::scope::Scope
source · pub struct Scope<'env, E: 'static> { /* private fields */ }
Expand description
Scope represents a concurrent computation bounded by lifetime 'env
.
Scope is constructed outside of the run()
call, so it cannot contain a strong reference
to the guards because we await scope termination within run()
call (which is triggered
by dropping the TerminateGuard).
Scope cannot be constructed inside of run()
call because the root task takes
&'env Scope
as an argument.
However the implementation guarantees that cancel_guard is non-null as long as there is at least 1 main task running, and that terminate_guard is non-null as long as ANY task is running.
Implementations§
source§impl<'env, E: 'static + Send> Scope<'env, E>
impl<'env, E: 'static + Send> Scope<'env, E>
sourcepub fn spawn_blocking<T: 'static + Send>(
&self,
f: impl 'env + Send + FnOnce() -> Result<T, E>,
) -> JoinHandle<'env, T>
pub fn spawn_blocking<T: 'static + Send>( &self, f: impl 'env + Send + FnOnce() -> Result<T, E>, ) -> JoinHandle<'env, T>
Spawns a blocking main task in the scope. This is NOT a blocking function, so it can be called from async context.
sourcepub fn spawn_bg_blocking<T: 'static + Send>(
&self,
f: impl 'env + Send + FnOnce() -> Result<T, E>,
) -> JoinHandle<'env, T>
pub fn spawn_bg_blocking<T: 'static + Send>( &self, f: impl 'env + Send + FnOnce() -> Result<T, E>, ) -> JoinHandle<'env, T>
Spawns a blocking background task in the scope. This is NOT a blocking function, so it can be called from async context.
sourcepub fn spawn<T: 'static + Send>(
&self,
f: impl 'env + Send + Future<Output = Result<T, E>>,
) -> JoinHandle<'env, T>
pub fn spawn<T: 'static + Send>( &self, f: impl 'env + Send + Future<Output = Result<T, E>>, ) -> JoinHandle<'env, T>
Spawns an async main task in the scope.
sourcepub fn spawn_bg<T: 'static + Send>(
&self,
f: impl 'env + Send + Future<Output = Result<T, E>>,
) -> JoinHandle<'env, T>
pub fn spawn_bg<T: 'static + Send>( &self, f: impl 'env + Send + Future<Output = Result<T, E>>, ) -> JoinHandle<'env, T>
Spawns an async background task in the scope.
sourcepub fn cancel(&self)
pub fn cancel(&self)
Immediately cancels the scope’s context. Normally all main tasks are expected to complete successfully before the context is canceled. You can use this method if you want to cancel immediately without returning an error (so that the whole scope can actually terminate successfully).