changeset 630:bf64ad2d36d1

Merge pull request #38 from hoprnet/feature/no-fs feature: Hide `PosixDiskEnv` type behind a feature (default enabled)
author Lewin Bormann <lbo@spheniscida.de>
date Thu, 14 Sep 2023 21:51:34 +0200
parents 2390a37c0086 (diff) e47c42a5801a (current diff)
children 685df78c5778
files
diffstat 1 files changed, 7 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/src/asyncdb.rs	Thu Sep 07 12:00:41 2023 +0200
+++ b/src/asyncdb.rs	Thu Sep 14 21:51:34 2023 +0200
@@ -1,5 +1,6 @@
 use std::collections::hash_map::HashMap;
 use std::path::Path;
+use std::sync::Arc;
 
 use crate::{Options, Result, Status, StatusCode, WriteBatch, DB};
 
@@ -45,8 +46,9 @@
 ///
 /// TODO: Make it work in other runtimes as well. This is a matter of adapting the blocking thread
 /// mechanism as well as the channel types.
+#[derive(Clone)]
 pub struct AsyncDB {
-    jh: JoinHandle<()>,
+    jh: Arc<JoinHandle<()>>,
     send: mpsc::Sender<Message>,
 }
 
@@ -56,7 +58,10 @@
         let db = DB::open(name, opts)?;
         let (send, recv) = mpsc::channel(CHANNEL_BUFFER_SIZE);
         let jh = spawn_blocking(move || AsyncDB::run_server(db, recv));
-        Ok(AsyncDB { jh, send })
+        Ok(AsyncDB {
+            jh: Arc::new(jh),
+            send,
+        })
     }
 
     pub async fn close(&self) -> Result<()> {