Skip to content

Commit

Permalink
use futures_channel::oneshot in sqlite worker
Browse files Browse the repository at this point in the history
  • Loading branch information
markazmierczak authored and abonander committed Nov 4, 2020
1 parent 6a5c54b commit 1d9ab52
Showing 1 changed file with 5 additions and 9 deletions.
14 changes: 5 additions & 9 deletions sqlx-core/src/sqlite/statement/worker.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
use crate::error::Error;
use crate::sqlite::statement::StatementHandle;
use crossbeam_channel::{bounded, unbounded, Sender};
use crossbeam_channel::{unbounded, Sender};
use either::Either;
use futures_channel::oneshot;
use libsqlite3_sys::{sqlite3_step, SQLITE_DONE, SQLITE_ROW};
use sqlx_rt::yield_now;
use std::thread;

// Each SQLite connection has a dedicated thread.
Expand All @@ -19,7 +19,7 @@ pub(crate) struct StatementWorker {
enum StatementWorkerCommand {
Step {
statement: StatementHandle,
tx: Sender<Result<Either<u64, ()>, Error>>,
tx: oneshot::Sender<Result<Either<u64, ()>, Error>>,
},
}

Expand Down Expand Up @@ -52,16 +52,12 @@ impl StatementWorker {
&mut self,
statement: StatementHandle,
) -> Result<Either<u64, ()>, Error> {
let (tx, rx) = bounded(1);
let (tx, rx) = oneshot::channel();

self.tx
.send(StatementWorkerCommand::Step { statement, tx })
.map_err(|_| Error::WorkerCrashed)?;

while rx.is_empty() {
yield_now().await;
}

rx.recv().map_err(|_| Error::WorkerCrashed)?
rx.await.map_err(|_| Error::WorkerCrashed)?
}
}

0 comments on commit 1d9ab52

Please sign in to comment.