-
Notifications
You must be signed in to change notification settings - Fork 249
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(driver-adapters): enable Wasm on
query-core
(#4445)
* feat(quaint): allow wasm32-unknown-unknown compilation; currently fails on native * feat(quaint): split postgres connector into native and wasm submodules * feat(quaint): split mysql connector into native and wasm submodules * feat(quaint): recover wasm error for mysql * feat(quaint): split mssql connector into native and wasm submodules * feat(quaint): split sqlite connector into native and wasm submodules * chore(quaint): fix clippy when compiling natively * chore(quaint): fix clippy when compiling to wasm32-unknown-unknown * chore(quaint): update README * chore(quaint): rename "*-connector" feature flag to "*-native" * feat(quaint): enable pure Wasm SqliteError * feat(query-connect): allow wasm32-unknown-unknown compilation * feat(sql-query-connector): allow wasm32-unknown-unknown compilation * chore(query-engine-wasm): add currently unused local crates to test wasm32-unknown-unknown compilation * chore: update Cargo.lock * chore: remove leftover comments * feat(query-core): allow wasm32-unknown-unknown compilation * chore(sql-query-connector): fix clipppy on wasm32 * chore: remove leftover comment * WIP: refactor mysql module to flatten its structure * feat(quaint): flatten mssql connector module * feat(quaint): flatten postgres connector module * feat(quaint): flatten sqlite connector module * chore(quaint): export all public definitions in connector "url" modules * chore(quaint): refactor tests for connectors, addressing feedback * chore: add comment on MysqlAsyncError * chore: add comment on ffi.rs for sqlite * chore: replace awkward "super::super::" with "crate::..." * chore: add comments around "query_core::executor::task" * chore: move "task" module into its own file * fix(driver-adapters): ci for "request-handlers" --------- Co-authored-by: Miguel Fernandez <[email protected]>
- Loading branch information
Showing
15 changed files
with
238 additions
and
14 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
//! This module provides a unified interface for spawning asynchronous tasks, regardless of the target platform. | ||
pub use arch::{spawn, JoinHandle}; | ||
use futures::Future; | ||
|
||
// On native targets, `tokio::spawn` spawns a new asynchronous task. | ||
#[cfg(not(target_arch = "wasm32"))] | ||
mod arch { | ||
use super::*; | ||
|
||
pub type JoinHandle<T> = tokio::task::JoinHandle<T>; | ||
|
||
pub fn spawn<T>(future: T) -> JoinHandle<T::Output> | ||
where | ||
T: Future + Send + 'static, | ||
T::Output: Send + 'static, | ||
{ | ||
tokio::spawn(future) | ||
} | ||
} | ||
|
||
// On Wasm targets, `wasm_bindgen_futures::spawn_local` spawns a new asynchronous task. | ||
#[cfg(target_arch = "wasm32")] | ||
mod arch { | ||
use super::*; | ||
use tokio::sync::oneshot::{self}; | ||
|
||
// Wasm-compatible alternative to `tokio::task::JoinHandle<T>`. | ||
// `pin_project` enables pin-projection and a `Pin`-compatible implementation of the `Future` trait. | ||
pub struct JoinHandle<T>(oneshot::Receiver<T>); | ||
|
||
impl<T> Future for JoinHandle<T> { | ||
type Output = Result<T, oneshot::error::RecvError>; | ||
|
||
fn poll(mut self: std::pin::Pin<&mut Self>, cx: &mut std::task::Context<'_>) -> std::task::Poll<Self::Output> { | ||
// the `self.project()` method is provided by the `pin_project` macro | ||
core::pin::Pin::new(&mut self.0).poll(cx) | ||
} | ||
} | ||
|
||
impl<T> JoinHandle<T> { | ||
pub fn abort(&mut self) { | ||
// abort is noop on Wasm targets | ||
} | ||
} | ||
|
||
pub fn spawn<T>(future: T) -> JoinHandle<T::Output> | ||
where | ||
T: Future + Send + 'static, | ||
T::Output: Send + 'static, | ||
{ | ||
let (sender, receiver) = oneshot::channel(); | ||
wasm_bindgen_futures::spawn_local(async move { | ||
let result = future.await; | ||
sender.send(result).ok(); | ||
}); | ||
JoinHandle(receiver) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.