mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-14 22:41:06 +00:00
Implement Executor for Service and SpawnHandle (#3007)
* Implement Executor for Service and SpawnHandle * Update lib.rs * Fix the race condition
This commit is contained in:
committed by
Gavin Wood
parent
81d8a5d01d
commit
fa535da069
@@ -119,10 +119,17 @@ pub struct SpawnTaskHandle {
|
|||||||
sender: mpsc::UnboundedSender<Box<dyn Future<Item = (), Error = ()> + Send>>,
|
sender: mpsc::UnboundedSender<Box<dyn Future<Item = (), Error = ()> + Send>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl SpawnTaskHandle {
|
impl Executor<Box<dyn Future<Item = (), Error = ()> + Send>> for SpawnTaskHandle {
|
||||||
/// Spawn a task to run the given future.
|
fn execute(
|
||||||
pub fn spawn_task(&self, task: impl Future<Item = (), Error = ()> + Send + 'static) {
|
&self,
|
||||||
let _ = self.sender.unbounded_send(Box::new(task));
|
future: Box<dyn Future<Item = (), Error = ()> + Send>
|
||||||
|
) -> Result<(), futures::future::ExecuteError<Box<dyn Future<Item = (), Error = ()> + Send>>> {
|
||||||
|
if let Err(err) = self.sender.unbounded_send(future) {
|
||||||
|
let kind = futures::future::ExecuteErrorKind::Shutdown;
|
||||||
|
Err(futures::future::ExecuteError::new(kind, err.into_inner()))
|
||||||
|
} else {
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -614,6 +621,22 @@ impl<Components> Future for Service<Components> where Components: components::Co
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl<Components> Executor<Box<dyn Future<Item = (), Error = ()> + Send>>
|
||||||
|
for Service<Components> where Components: components::Components
|
||||||
|
{
|
||||||
|
fn execute(
|
||||||
|
&self,
|
||||||
|
future: Box<dyn Future<Item = (), Error = ()> + Send>
|
||||||
|
) -> Result<(), futures::future::ExecuteError<Box<dyn Future<Item = (), Error = ()> + Send>>> {
|
||||||
|
if let Err(err) = self.to_spawn_tx.unbounded_send(future) {
|
||||||
|
let kind = futures::future::ExecuteErrorKind::Shutdown;
|
||||||
|
Err(futures::future::ExecuteError::new(kind, err.into_inner()))
|
||||||
|
} else {
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// Builds a never-ending future that continuously polls the network.
|
/// Builds a never-ending future that continuously polls the network.
|
||||||
///
|
///
|
||||||
/// The `status_sink` contain a list of senders to send a periodic network status to.
|
/// The `status_sink` contain a list of senders to send a periodic network status to.
|
||||||
|
|||||||
Reference in New Issue
Block a user