Struct vfs::execution_scope::ExecutionScope
source · pub struct ExecutionScope { /* private fields */ }
Expand description
An execution scope that is hosting tasks for a group of connections. See the module level documentation for details.
Actual execution will be delegated to an “upstream” executor - something that implements
[futures::task::Spawn
]. In a sense, this is somewhat of an analog of a multithreaded capable
[futures::stream::FuturesUnordered
], but this some additional functionality specific to the
vfs library.
Use ExecutionScope::new()
or ExecutionScope::build()
to construct new
ExecutionScope
es.
Implementations§
source§impl ExecutionScope
impl ExecutionScope
sourcepub fn new() -> Self
pub fn new() -> Self
Constructs an execution scope. Use ExecutionScope::build()
if you want to specify
parameters.
sourcepub fn build() -> ExecutionScopeParams
pub fn build() -> ExecutionScopeParams
Constructs a new execution scope builder, wrapping the specified executor and optionally
accepting additional parameters. Run ExecutionScopeParams::new()
to get an actual
ExecutionScope
object.
sourcepub fn active_count(&self) -> usize
pub fn active_count(&self) -> usize
Returns the active count: the number of tasks that are active and will prevent shutdown.
sourcepub fn spawn(
&self,
task: impl Future<Output = ()> + Send + 'static,
) -> JoinHandle<()>
pub fn spawn( &self, task: impl Future<Output = ()> + Send + 'static, ) -> JoinHandle<()>
Sends a task
to be executed in this execution scope. This is very similar to
[futures::task::Spawn::spawn_obj()
] with a minor difference that self
reference is not
exclusive.
If the task needs to prevent itself from being shutdown, then it should use the
try_active_guard
function below.
For the “vfs” library it is more convenient that this method allows non-exclusive
access. And as the implementation is employing internal mutability there are no downsides.
This way ExecutionScope
can actually also implement [futures::task::Spawn
] - it just was
not necessary for now.
pub fn token_registry(&self) -> &TokenRegistry
pub fn shutdown(&self)
sourcepub fn force_shutdown(&self)
pub fn force_shutdown(&self)
Forcibly shut down the executor without respecting the active guards.
sourcepub fn resurrect(&self)
pub fn resurrect(&self)
Restores the executor so that it is no longer in the shut-down state. Any tasks that are still running will continue to run after calling this.
sourcepub fn try_active_guard(&self) -> Option<ActiveGuard>
pub fn try_active_guard(&self) -> Option<ActiveGuard>
Prevents the executor from shutting down whilst the guard is held. Returns None if the executor is shutting down.
sourcepub fn active_guard(&self) -> ActiveGuard
pub fn active_guard(&self) -> ActiveGuard
As above, but succeeds even if the executor is shutting down. This can be used in drop implementations to spawn tasks that must run before the executor shuts down.
Trait Implementations§
source§impl Clone for ExecutionScope
impl Clone for ExecutionScope
source§fn clone(&self) -> ExecutionScope
fn clone(&self) -> ExecutionScope
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moresource§impl Debug for ExecutionScope
impl Debug for ExecutionScope
source§impl PartialEq for ExecutionScope
impl PartialEq for ExecutionScope
impl Eq for ExecutionScope
Auto Trait Implementations§
impl Freeze for ExecutionScope
impl !RefUnwindSafe for ExecutionScope
impl Send for ExecutionScope
impl Sync for ExecutionScope
impl Unpin for ExecutionScope
impl !UnwindSafe for ExecutionScope
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§default unsafe fn clone_to_uninit(&self, dst: *mut T)
default unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)