Mercurial > lbo > hg > leveldb-rs
changeset 622:8fec6e2bd06c
Make `AsyncDB` clonable
author | Velnbur <kyrylo.baybula@distributedlab.com> |
---|---|
date | Fri, 08 Sep 2023 12:45:58 +0300 |
parents | dbf8977e966a |
children | 2390a37c0086 |
files | src/asyncdb.rs |
diffstat | 1 files changed, 7 insertions(+), 2 deletions(-) [+] |
line wrap: on
line diff
--- a/src/asyncdb.rs Thu Aug 31 08:01:36 2023 +0200 +++ b/src/asyncdb.rs Fri Sep 08 12:45:58 2023 +0300 @@ -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<()> {