Expose that BasicQueue expects blocking spawn (#5860)

* Expose that `BasicQueue` expects blocking spawn

Up to now `BasicQueue` expected a closure that to spawn a `Future`.
This was expected to be a closure that spawns a blocking future.
However, this wasn't documented anywhere. This pr introduces a new trait
`SpawnBlocking` that exposes this requirement to the outside.

* Feedback
This commit is contained in:
Bastian Köcher
2020-05-04 19:40:29 +02:00
committed by GitHub
parent 8549cf5899
commit 9c5536e01a
15 changed files with 90 additions and 48 deletions
+14 -3
View File
@@ -15,10 +15,10 @@
use std::{panic, pin::Pin, result::Result, sync::Arc};
use exit_future::Signal;
use log::{debug};
use log::debug;
use futures::{
Future, FutureExt,
future::{select, Either},
future::{select, Either, BoxFuture},
compat::*,
task::{Spawn, FutureObj, SpawnError},
};
@@ -62,7 +62,12 @@ impl SpawnTaskHandle {
}
/// Helper function that implements the spawning logic. See `spawn` and `spawn_blocking`.
fn spawn_inner(&self, name: &'static str, task: impl Future<Output = ()> + Send + 'static, task_type: TaskType) {
fn spawn_inner(
&self,
name: &'static str,
task: impl Future<Output = ()> + Send + 'static,
task_type: TaskType,
) {
let on_exit = self.on_exit.clone();
let metrics = self.metrics.clone();
@@ -119,6 +124,12 @@ impl Spawn for SpawnTaskHandle {
}
}
impl sp_core::traits::SpawnBlocking for SpawnTaskHandle {
fn spawn_blocking(&self, name: &'static str, future: BoxFuture<'static, ()>) {
self.spawn_blocking(name, future);
}
}
impl sc_client_api::CloneableSpawn for SpawnTaskHandle {
fn clone(&self) -> Box<dyn CloneableSpawn> {
Box::new(Clone::clone(self))