mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-15 16:11:05 +00:00
Add spawn_blocking to SubsystemContext (#1570)
* subsystem: add spawn_blocking to SubsystemContext * candidate-validation: use spawn_blocking for exhaustive tasks
This commit is contained in:
@@ -318,7 +318,7 @@ async fn spawn_validate_exhaustive(
|
|||||||
let _ = tx.send(res);
|
let _ = tx.send(res);
|
||||||
};
|
};
|
||||||
|
|
||||||
ctx.spawn("blocking-candidate-validation-task", fut.boxed()).await?;
|
ctx.spawn_blocking("blocking-candidate-validation-task", fut.boxed()).await?;
|
||||||
rx.await.map_err(Into::into)
|
rx.await.map_err(Into::into)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -112,6 +112,13 @@ enum ToOverseer {
|
|||||||
name: &'static str,
|
name: &'static str,
|
||||||
s: BoxFuture<'static, ()>,
|
s: BoxFuture<'static, ()>,
|
||||||
},
|
},
|
||||||
|
|
||||||
|
/// Same as `SpawnJob` but for blocking tasks to be executed on a
|
||||||
|
/// dedicated thread pool.
|
||||||
|
SpawnBlockingJob {
|
||||||
|
name: &'static str,
|
||||||
|
s: BoxFuture<'static, ()>,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
/// An event telling the `Overseer` on the particular block
|
/// An event telling the `Overseer` on the particular block
|
||||||
@@ -238,7 +245,8 @@ impl Debug for ToOverseer {
|
|||||||
ToOverseer::SubsystemMessage(msg) => {
|
ToOverseer::SubsystemMessage(msg) => {
|
||||||
write!(f, "OverseerMessage::SubsystemMessage({:?})", msg)
|
write!(f, "OverseerMessage::SubsystemMessage({:?})", msg)
|
||||||
}
|
}
|
||||||
ToOverseer::SpawnJob { .. } => write!(f, "OverseerMessage::Spawn(..)")
|
ToOverseer::SpawnJob { .. } => write!(f, "OverseerMessage::Spawn(..)"),
|
||||||
|
ToOverseer::SpawnBlockingJob { .. } => write!(f, "OverseerMessage::SpawnBlocking(..)")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -290,6 +298,17 @@ impl<M: Send + 'static> SubsystemContext for OverseerSubsystemContext<M> {
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async fn spawn_blocking(&mut self, name: &'static str, s: Pin<Box<dyn Future<Output = ()> + Send>>)
|
||||||
|
-> SubsystemResult<()>
|
||||||
|
{
|
||||||
|
self.tx.send(ToOverseer::SpawnBlockingJob {
|
||||||
|
name,
|
||||||
|
s,
|
||||||
|
}).await?;
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
async fn send_message(&mut self, msg: AllMessages) -> SubsystemResult<()> {
|
async fn send_message(&mut self, msg: AllMessages) -> SubsystemResult<()> {
|
||||||
self.tx.send(ToOverseer::SubsystemMessage(msg)).await?;
|
self.tx.send(ToOverseer::SubsystemMessage(msg)).await?;
|
||||||
|
|
||||||
@@ -803,6 +822,9 @@ where
|
|||||||
ToOverseer::SpawnJob { name, s } => {
|
ToOverseer::SpawnJob { name, s } => {
|
||||||
self.spawn_job(name, s);
|
self.spawn_job(name, s);
|
||||||
}
|
}
|
||||||
|
ToOverseer::SpawnBlockingJob { name, s } => {
|
||||||
|
self.spawn_blocking_job(name, s);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -992,6 +1014,10 @@ where
|
|||||||
fn spawn_job(&mut self, name: &'static str, j: BoxFuture<'static, ()>) {
|
fn spawn_job(&mut self, name: &'static str, j: BoxFuture<'static, ()>) {
|
||||||
self.s.spawn(name, j);
|
self.s.spawn(name, j);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn spawn_blocking_job(&mut self, name: &'static str, j: BoxFuture<'static, ()>) {
|
||||||
|
self.s.spawn_blocking(name, j);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn spawn<S: SpawnNamed, M: Send + 'static>(
|
fn spawn<S: SpawnNamed, M: Send + 'static>(
|
||||||
|
|||||||
@@ -177,6 +177,13 @@ impl<M: Send + 'static, S: SpawnNamed + Send + 'static> SubsystemContext for Tes
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async fn spawn_blocking(&mut self, name: &'static str, s: Pin<Box<dyn Future<Output = ()> + Send>>)
|
||||||
|
-> SubsystemResult<()>
|
||||||
|
{
|
||||||
|
self.spawn.spawn_blocking(name, s);
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
async fn send_message(&mut self, msg: AllMessages) -> SubsystemResult<()> {
|
async fn send_message(&mut self, msg: AllMessages) -> SubsystemResult<()> {
|
||||||
self.tx.send(msg).await.expect("test overseer no longer live");
|
self.tx.send(msg).await.expect("test overseer no longer live");
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|||||||
@@ -178,6 +178,13 @@ pub trait SubsystemContext: Send + 'static {
|
|||||||
/// Spawn a child task on the executor.
|
/// Spawn a child task on the executor.
|
||||||
async fn spawn(&mut self, name: &'static str, s: Pin<Box<dyn Future<Output = ()> + Send>>) -> SubsystemResult<()>;
|
async fn spawn(&mut self, name: &'static str, s: Pin<Box<dyn Future<Output = ()> + Send>>) -> SubsystemResult<()>;
|
||||||
|
|
||||||
|
/// Spawn a blocking child task on the executor's dedicated thread pool.
|
||||||
|
async fn spawn_blocking(
|
||||||
|
&mut self,
|
||||||
|
name: &'static str,
|
||||||
|
s: Pin<Box<dyn Future<Output = ()> + Send>>,
|
||||||
|
) -> SubsystemResult<()>;
|
||||||
|
|
||||||
/// Send a direct message to some other `Subsystem`, routed based on message type.
|
/// Send a direct message to some other `Subsystem`, routed based on message type.
|
||||||
async fn send_message(&mut self, msg: AllMessages) -> SubsystemResult<()>;
|
async fn send_message(&mut self, msg: AllMessages) -> SubsystemResult<()>;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user