From e3f8f4b732acb60c93101318e91cc4a039e94cb6 Mon Sep 17 00:00:00 2001 From: Thomas Heck Date: Tue, 9 Mar 2021 21:03:36 +0100 Subject: [PATCH] feat: use `agnostik` as "agnostic" async executor --- crdt-enc/src/lib.rs | 18 +----------------- examples/test/Cargo.toml | 1 + examples/test/src/main.rs | 14 -------------- 3 files changed, 2 insertions(+), 31 deletions(-) diff --git a/crdt-enc/src/lib.rs b/crdt-enc/src/lib.rs index 01bfbf3..d30cd47 100644 --- a/crdt-enc/src/lib.rs +++ b/crdt-enc/src/lib.rs @@ -16,7 +16,6 @@ use ::dyn_clone::DynClone; use ::futures::{ lock::Mutex as AsyncMutex, stream::{self, StreamExt, TryStreamExt}, - task, }; use ::serde::{de::DeserializeOwned, Deserialize, Serialize}; use ::std::{ @@ -34,7 +33,7 @@ const SUPPORTED_VERSIONS: &[Uuid] = &[ #[async_trait] pub trait CoreSubHandle where - Self: 'static + Debug + Send + Sync + DynClone + task::Spawn, + Self: 'static + Debug + Send + Sync + DynClone, { fn info(&self) -> Info; @@ -52,16 +51,6 @@ where ) -> Result<()>; } -impl task::Spawn for Core { - fn spawn_obj(&self, future: task::FutureObj<'static, ()>) -> Result<(), task::SpawnError> { - self.spawn.spawn_obj(future) - } - - fn status(&self) -> Result<(), task::SpawnError> { - self.spawn.status() - } -} - #[async_trait] impl CoreSubHandle for Arc> where @@ -196,11 +185,8 @@ where // } // } -pub trait CoreSpawn: task::Spawn + Debug + Send + Sync {} - #[derive(Debug)] pub struct Core { - spawn: Box, storage: ST, cryptor: C, key_cryptor: KC, @@ -242,7 +228,6 @@ where supported_data_versions.sort_unstable(); let core = Arc::new(Core { - spawn: options.spawn, storage: options.storage, cryptor: options.cryptor, key_cryptor: options.key_cryptor, @@ -741,7 +726,6 @@ where } pub struct OpenOptions { - pub spawn: Box, pub storage: ST, pub cryptor: C, pub key_cryptor: KC, diff --git a/examples/test/Cargo.toml b/examples/test/Cargo.toml index b25b0e9..4379004 100644 --- a/examples/test/Cargo.toml +++ b/examples/test/Cargo.toml @@ -14,3 +14,4 @@ crdts = "6.2" tokio = {version = "1", features = ["macros", "rt"]} anyhow = "1" futures = "0.3" +agnostik = {git = "https://github.com/chpio/agnostik.git", branch = "tokio1", features = ["runtime_tokio"]} diff --git a/examples/test/src/main.rs b/examples/test/src/main.rs index 0d8d074..934c52c 100644 --- a/examples/test/src/main.rs +++ b/examples/test/src/main.rs @@ -2,24 +2,11 @@ use ::anyhow::Result; use ::crdt_enc_gpgme::KeyHandler; use ::crdt_enc_tokio::Storage; use ::crdt_enc_xchacha20poly1305::EncHandler; -use ::futures::task; use ::uuid::Uuid; const CURRENT_DATA_VERSION: Uuid = Uuid::from_u128(0xaadfd5a6_6e19_4b24_a802_4fa27c72f20c); const SUPPORTED_DATA_VERSIONS: &[Uuid] = &[CURRENT_DATA_VERSION]; -#[derive(Debug)] -struct TokioSpawn; - -impl crdt_enc::CoreSpawn for TokioSpawn {} - -impl task::Spawn for TokioSpawn { - fn spawn_obj(&self, future: task::FutureObj<'static, ()>) -> Result<(), task::SpawnError> { - // drop tokios `JoinHandle` - tokio::spawn(future); - Ok(()) - } -} #[tokio::main(flavor = "current_thread")] async fn main() -> Result<()> { @@ -29,7 +16,6 @@ async fn main() -> Result<()> { let cryptor = EncHandler::new(); let key_cryptor = KeyHandler::new(); let open_options = crdt_enc::OpenOptions { - spawn: Box::new(TokioSpawn), storage, cryptor, key_cryptor,