Skip to content

Commit

Permalink
Merge pull request #40 from Velnbur/master
Browse files Browse the repository at this point in the history
Make `AsyncDB` clonable
  • Loading branch information
dermesser authored Sep 8, 2023
2 parents e2d7a4e + 4ab91e2 commit c467d3f
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/asyncdb.rs
Original file line number Diff line number Diff line change
@@ -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};

Expand Down Expand Up @@ -45,8 +46,9 @@ struct Message {
///
/// 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>,
}

Expand All @@ -56,7 +58,10 @@ impl AsyncDB {
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<()> {
Expand Down

0 comments on commit c467d3f

Please sign in to comment.