pub struct SpawnRequestBuilder<C: ClosureKind> { /* private fields */ }Expand description
A builder for configuring new tasks to spawn.
The builder allows us to set up several different flavors of possible tasks to spawn, with a menu of options as follows:
- A task may or may not have a name.
- A task may or may not have an assigned scheduler role.
- A task may be a sync, or an async closure.
- A task may return a result, or may not return a result.
- The task’s result can be collected synchronously, asynchronously, or not collected at all.
Note that these parameters are not perfectly orthogonal. For example, a task spawned from an async closure can not return a value asynchronously. (This is not a limitation of the approach, rather it’s the API that we explicitly use today.) Also, some parameter combinations do not make sense, for example a spawn request can not have both a sync and an async closure to run.
The builder API is designed in a way that only allows chaining the configuration options which are valid at that point in the configuration process. Invalid option combinations are compile-time(!) errors. It will only allow creating a SpawnRequest if enough parameters have been passed such that there is enough information to create a request. It will not allow passing conflicting parameters: for example, if you already passed one synchronous closure, it is impossible to pass another closure and have the code compile without errors.
§Usage
Call SpawnRequestBuilder::new() to start building. Refer to the unit tests in this module for usage examples.
Implementations§
Source§impl SpawnRequestBuilder<ClosureNone>
You can only create an empty request builder.
impl SpawnRequestBuilder<ClosureNone>
You can only create an empty request builder.
Source§impl<C: ClosureKind> SpawnRequestBuilder<C>
You can call these at any point in the builder’s lifecycle.
impl<C: ClosureKind> SpawnRequestBuilder<C>
You can call these at any point in the builder’s lifecycle.
Source§impl SpawnRequestBuilder<ClosureNone>
You can call these only if you have not provided a closure yet.
impl SpawnRequestBuilder<ClosureNone>
You can call these only if you have not provided a closure yet.
Sourcepub fn with_sync_closure<F, T>(
self,
f: F,
) -> SpawnRequestBuilder<impl FnOnce(&mut Locked<Unlocked>, &CurrentTask) -> T + Send + 'static>
pub fn with_sync_closure<F, T>( self, f: F, ) -> SpawnRequestBuilder<impl FnOnce(&mut Locked<Unlocked>, &CurrentTask) -> T + Send + 'static>
Provides the closure that the spawner will run.
Sourcepub fn with_async_closure<F, T>(
self,
f: F,
) -> SpawnRequestBuilder<impl FnOnce(&mut Locked<Unlocked>, &CurrentTask) -> T + Send + 'static>
pub fn with_async_closure<F, T>( self, f: F, ) -> SpawnRequestBuilder<impl FnOnce(&mut Locked<Unlocked>, &CurrentTask) -> T + Send + 'static>
Provides the closure that the spawner will run.
Source§impl<T, F> SpawnRequestBuilder<F>
impl<T, F> SpawnRequestBuilder<F>
Sourcepub fn build(self) -> SpawnRequest
pub fn build(self) -> SpawnRequest
Build a spawn request.
Sourcepub fn build_with_sync_result(
self,
) -> (impl FnOnce() -> Result<T, Errno>, SpawnRequest)
pub fn build_with_sync_result( self, ) -> (impl FnOnce() -> Result<T, Errno>, SpawnRequest)
Like [build], but allows receiving a result synchronously. Do not forget to submit the spawn request to a spawner.
Example:
let (result_fn, request) = /*...*/ .build_with_sync_result();
// spawn `request`
let result = result_fn();Sourcepub fn build_with_async_result(
self,
) -> (impl Future<Output = Result<T, Errno>>, SpawnRequest)
pub fn build_with_async_result( self, ) -> (impl Future<Output = Result<T, Errno>>, SpawnRequest)
Like [build], but allows receiving a result as a future. Do not forget to submit the spawn request to a spawner.
Example:
let (result_fut, request) = /*...*/ .build_with_async_result();
// spawn `request`
let result = result_fut.await;Auto Trait Implementations§
impl<C> Freeze for SpawnRequestBuilder<C>where
C: Freeze,
impl<C> RefUnwindSafe for SpawnRequestBuilder<C>where
C: RefUnwindSafe,
impl<C> Send for SpawnRequestBuilder<C>where
C: Send,
impl<C> Sync for SpawnRequestBuilder<C>where
C: Sync,
impl<C> Unpin for SpawnRequestBuilder<C>where
C: Unpin,
impl<C> UnwindSafe for SpawnRequestBuilder<C>where
C: UnwindSafe,
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, D> Encode<Ambiguous1, D> for Twhere
D: ResourceDialect,
impl<T, D> Encode<Ambiguous1, D> for Twhere
D: ResourceDialect,
Source§impl<T, D> Encode<Ambiguous2, D> for Twhere
D: ResourceDialect,
impl<T, D> Encode<Ambiguous2, D> for Twhere
D: ResourceDialect,
§impl<T> InstanceFromServiceTransport<T> for T
impl<T> InstanceFromServiceTransport<T> for T
§fn from_service_transport(handle: T) -> T
fn from_service_transport(handle: T) -> T
T to [Self]Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more