feat: impl Spawn for Core

so that sub systems are able to spawn tasks
This commit is contained in:
2021-02-21 18:00:26 +01:00
parent 5b928c96f9
commit c0a099909e
3 changed files with 31 additions and 3 deletions

View File

@@ -2,11 +2,24 @@ use ::anyhow::Result;
use ::crdt_enc_gpgme::KeyHandler;
use ::crdt_enc_sodium::EncHandler;
use ::crdt_enc_tokio::Storage;
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<()> {
@@ -18,6 +31,7 @@ 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,