mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-04-27 20:57:59 +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:
@@ -112,6 +112,13 @@ enum ToOverseer {
|
||||
name: &'static str,
|
||||
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
|
||||
@@ -238,7 +245,8 @@ impl Debug for ToOverseer {
|
||||
ToOverseer::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(())
|
||||
}
|
||||
|
||||
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<()> {
|
||||
self.tx.send(ToOverseer::SubsystemMessage(msg)).await?;
|
||||
|
||||
@@ -803,6 +822,9 @@ where
|
||||
ToOverseer::SpawnJob { 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, ()>) {
|
||||
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>(
|
||||
|
||||
Reference in New Issue
Block a user