feat: use agnostik as "agnostic" async executor
This commit is contained in:
@@ -16,7 +16,6 @@ use ::dyn_clone::DynClone;
|
|||||||
use ::futures::{
|
use ::futures::{
|
||||||
lock::Mutex as AsyncMutex,
|
lock::Mutex as AsyncMutex,
|
||||||
stream::{self, StreamExt, TryStreamExt},
|
stream::{self, StreamExt, TryStreamExt},
|
||||||
task,
|
|
||||||
};
|
};
|
||||||
use ::serde::{de::DeserializeOwned, Deserialize, Serialize};
|
use ::serde::{de::DeserializeOwned, Deserialize, Serialize};
|
||||||
use ::std::{
|
use ::std::{
|
||||||
@@ -34,7 +33,7 @@ const SUPPORTED_VERSIONS: &[Uuid] = &[
|
|||||||
#[async_trait]
|
#[async_trait]
|
||||||
pub trait CoreSubHandle
|
pub trait CoreSubHandle
|
||||||
where
|
where
|
||||||
Self: 'static + Debug + Send + Sync + DynClone + task::Spawn,
|
Self: 'static + Debug + Send + Sync + DynClone,
|
||||||
{
|
{
|
||||||
fn info(&self) -> Info;
|
fn info(&self) -> Info;
|
||||||
|
|
||||||
@@ -52,16 +51,6 @@ where
|
|||||||
) -> Result<()>;
|
) -> Result<()>;
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<S, ST, C, KC> task::Spawn for Core<S, ST, C, KC> {
|
|
||||||
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]
|
#[async_trait]
|
||||||
impl<S, ST, C, KC> CoreSubHandle for Arc<Core<S, ST, C, KC>>
|
impl<S, ST, C, KC> CoreSubHandle for Arc<Core<S, ST, C, KC>>
|
||||||
where
|
where
|
||||||
@@ -196,11 +185,8 @@ where
|
|||||||
// }
|
// }
|
||||||
// }
|
// }
|
||||||
|
|
||||||
pub trait CoreSpawn: task::Spawn + Debug + Send + Sync {}
|
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct Core<S, ST, C, KC> {
|
pub struct Core<S, ST, C, KC> {
|
||||||
spawn: Box<dyn CoreSpawn>,
|
|
||||||
storage: ST,
|
storage: ST,
|
||||||
cryptor: C,
|
cryptor: C,
|
||||||
key_cryptor: KC,
|
key_cryptor: KC,
|
||||||
@@ -242,7 +228,6 @@ where
|
|||||||
supported_data_versions.sort_unstable();
|
supported_data_versions.sort_unstable();
|
||||||
|
|
||||||
let core = Arc::new(Core {
|
let core = Arc::new(Core {
|
||||||
spawn: options.spawn,
|
|
||||||
storage: options.storage,
|
storage: options.storage,
|
||||||
cryptor: options.cryptor,
|
cryptor: options.cryptor,
|
||||||
key_cryptor: options.key_cryptor,
|
key_cryptor: options.key_cryptor,
|
||||||
@@ -741,7 +726,6 @@ where
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub struct OpenOptions<ST, C, KC> {
|
pub struct OpenOptions<ST, C, KC> {
|
||||||
pub spawn: Box<dyn CoreSpawn>,
|
|
||||||
pub storage: ST,
|
pub storage: ST,
|
||||||
pub cryptor: C,
|
pub cryptor: C,
|
||||||
pub key_cryptor: KC,
|
pub key_cryptor: KC,
|
||||||
|
|||||||
@@ -14,3 +14,4 @@ crdts = "6.2"
|
|||||||
tokio = {version = "1", features = ["macros", "rt"]}
|
tokio = {version = "1", features = ["macros", "rt"]}
|
||||||
anyhow = "1"
|
anyhow = "1"
|
||||||
futures = "0.3"
|
futures = "0.3"
|
||||||
|
agnostik = {git = "https://github.com/chpio/agnostik.git", branch = "tokio1", features = ["runtime_tokio"]}
|
||||||
|
|||||||
@@ -2,24 +2,11 @@ use ::anyhow::Result;
|
|||||||
use ::crdt_enc_gpgme::KeyHandler;
|
use ::crdt_enc_gpgme::KeyHandler;
|
||||||
use ::crdt_enc_tokio::Storage;
|
use ::crdt_enc_tokio::Storage;
|
||||||
use ::crdt_enc_xchacha20poly1305::EncHandler;
|
use ::crdt_enc_xchacha20poly1305::EncHandler;
|
||||||
use ::futures::task;
|
|
||||||
use ::uuid::Uuid;
|
use ::uuid::Uuid;
|
||||||
|
|
||||||
const CURRENT_DATA_VERSION: Uuid = Uuid::from_u128(0xaadfd5a6_6e19_4b24_a802_4fa27c72f20c);
|
const CURRENT_DATA_VERSION: Uuid = Uuid::from_u128(0xaadfd5a6_6e19_4b24_a802_4fa27c72f20c);
|
||||||
|
|
||||||
const SUPPORTED_DATA_VERSIONS: &[Uuid] = &[CURRENT_DATA_VERSION];
|
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")]
|
#[tokio::main(flavor = "current_thread")]
|
||||||
async fn main() -> Result<()> {
|
async fn main() -> Result<()> {
|
||||||
@@ -29,7 +16,6 @@ async fn main() -> Result<()> {
|
|||||||
let cryptor = EncHandler::new();
|
let cryptor = EncHandler::new();
|
||||||
let key_cryptor = KeyHandler::new();
|
let key_cryptor = KeyHandler::new();
|
||||||
let open_options = crdt_enc::OpenOptions {
|
let open_options = crdt_enc::OpenOptions {
|
||||||
spawn: Box::new(TokioSpawn),
|
|
||||||
storage,
|
storage,
|
||||||
cryptor,
|
cryptor,
|
||||||
key_cryptor,
|
key_cryptor,
|
||||||
|
|||||||
Reference in New Issue
Block a user