Skip to content

Instantly share code, notes, and snippets.

@pjenvey
Created October 18, 2018 20:40
Show Gist options
  • Save pjenvey/7fd511843bd218dfd990d513bf5fc737 to your computer and use it in GitHub Desktop.
Save pjenvey/7fd511843bd218dfd990d513bf5fc737 to your computer and use it in GitHub Desktop.
use db::{Db, DbFuture, DbPool};
impl DbPool for MysqlDbPool {
//type Db = MysqlDb;
//fn get(&self) -> DbFuture<Self::Db> {
fn get(&self) -> DbFuture<Box<Db>> {
// XXX:
use futures::future::poll_fn;
use futures::Future;
use tokio_threadpool::blocking;
let s = self.clone();
Box::new(
poll_fn(move || {
blocking(|| s.get_sync().map(|db| Box::new(db) as Box<Db>))
.map_err(|_| panic!("Database queries must be run inside a Tokio thread pool!"))
}).and_then(|r| r),
)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment