mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-04-27 09:17:58 +00:00
Name all the tasks! (#6726)
* Remove any implementation of `Spawn` or `Executor` from our task executors * Fix compilation * Rename `SpawnBlockingExecutor` * Update primitives/core/src/traits.rs Co-authored-by: Kian Paimani <5588131+kianenigma@users.noreply.github.com> * Fix tests Co-authored-by: Kian Paimani <5588131+kianenigma@users.noreply.github.com>
This commit is contained in:
@@ -61,7 +61,7 @@ impl Default for TestSetup {
|
||||
let client_builder = substrate_test_runtime_client::TestClientBuilder::new();
|
||||
let client = Arc::new(client_builder.set_keystore(keystore.clone()).build());
|
||||
|
||||
let spawner = sp_core::testing::SpawnBlockingExecutor::new();
|
||||
let spawner = sp_core::testing::TaskExecutor::new();
|
||||
let pool = BasicPool::new_full(
|
||||
Default::default(),
|
||||
Arc::new(FullChainApi::new(client.clone(), None)),
|
||||
|
||||
@@ -22,6 +22,11 @@
|
||||
|
||||
#![warn(missing_docs)]
|
||||
|
||||
use futures::{compat::Future01CompatExt, FutureExt};
|
||||
use rpc::futures::future::{Executor, ExecuteError, Future};
|
||||
use sp_core::traits::SpawnNamed;
|
||||
use std::sync::Arc;
|
||||
|
||||
mod metadata;
|
||||
|
||||
pub use sc_rpc_api::DenyUnsafe;
|
||||
@@ -35,3 +40,24 @@ pub mod state;
|
||||
pub mod system;
|
||||
#[cfg(test)]
|
||||
mod testing;
|
||||
|
||||
/// Task executor that is being used by RPC subscriptions.
|
||||
#[derive(Clone)]
|
||||
pub struct SubscriptionTaskExecutor(Arc<dyn SpawnNamed>);
|
||||
|
||||
impl SubscriptionTaskExecutor {
|
||||
/// Create a new `Self` with the given spawner.
|
||||
pub fn new(spawn: impl SpawnNamed + 'static) -> Self {
|
||||
Self(Arc::new(spawn))
|
||||
}
|
||||
}
|
||||
|
||||
impl Executor<Box<dyn Future<Item = (), Error = ()> + Send>> for SubscriptionTaskExecutor {
|
||||
fn execute(
|
||||
&self,
|
||||
future: Box<dyn Future<Item = (), Error = ()> + Send>,
|
||||
) -> Result<(), ExecuteError<Box<dyn Future<Item = (), Error = ()> + Send>>> {
|
||||
self.0.spawn("substrate_rpc_subscription", future.compat().map(drop).boxed());
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user