pub trait BinderAsyncPool {
// Required method
fn spawn<'a, F1, F2, Fut, A, B, E>(
spawn_me: F1,
after_spawn: F2,
) -> BoxFuture<'a, Result<B, E>>
where F1: FnOnce() -> A + Send + 'static,
F2: FnOnce(A) -> Fut + Send + 'a,
Fut: Future<Output = Result<B, E>> + Send + 'a,
A: Send + 'static,
B: Send + 'a,
E: From<StatusCode>;
}
Expand description
A thread pool for running binder transactions.
Required Methods§
Sourcefn spawn<'a, F1, F2, Fut, A, B, E>(
spawn_me: F1,
after_spawn: F2,
) -> BoxFuture<'a, Result<B, E>>
fn spawn<'a, F1, F2, Fut, A, B, E>( spawn_me: F1, after_spawn: F2, ) -> BoxFuture<'a, Result<B, E>>
This function should conceptually behave like this:
let result = spawn_thread(|| spawn_me()).await;
return after_spawn(result).await;
If the spawning fails for some reason, the method may also skip the after_spawn
closure
and immediately return an error.
The only difference between different implementations should be which
spawn_thread
method is used. For Tokio, it would be tokio::task::spawn_blocking
.
This method has the design it has because the only way to define a trait that
allows the return type of the spawn to be chosen by the caller is to return a
boxed Future
trait object, and including after_spawn
in the trait function
allows the caller to avoid double-boxing if they want to do anything to the value
returned from the spawned thread.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.