-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Wasm futures #72
Wasm futures #72
Conversation
Can you explain how the |
So there's wasm and wasm... In browser, where everything becomes a Javascript object, futures are ?Send Also, reqwest responses are not Send. It seems like it boils down to the fetch api returning a js_sys::Promise, which is !Send With some hacks, it is possible though: https://users.rust-lang.org/t/is-it-possible-to-take-a-jsfuture-as-send/97774 but yeah, I think maybe specifying it further as suggested here: #[cfg_attr(all(target_family = "wasm", target_os = "unknown"), async_trait(?Send)]
#[cfg_attr(not(all(target_family = "wasm", target_os = "unknown")), async_trait] I don't know why and how |
This |
interesting... |
Ok, you're right, I'm wrong... use wasm_bindgen::spawn_local; // added `spawn_local`
pub struct WasmReader {
inner: Arc<dyn NotSendAsyncFileReader>
}
impl AsyncFileReader for WasmReader {
async fn get_bytes(&self, range: Range<u64>) -> BoxFuture<'_, AsyncTiffResult<Bytes>> {
let (rx, tx) = oneshot::new()
let inner = self.inner.clone()
spawn_local(async move {
tx.send(inner.get_bytes(range).await) // this task is not Send, but that's ok since we don't use any references
})
rx.await // channel receive is Send!!!
}
} The trick then is to have the main functionality defined in some loose There's quite some weeds also, where wasm-bindgen plays a lot of magic tricks, but in the end it was indeed parquet-wasm that had the solution :D anyways.... Still there may be a nice solution, or does that need its own crate, like parquet-wasm? feel free to close this PR or suggest a way forward. Thanks for the guidance :) |
It's not really a middleware because it's not wrapping anything. You just need this implementation: https://github.com/kylebarron/parquet-wasm/blob/e85322b592ab224938861895a06f4f3947a77802/src/reader_async.rs#L230-L291 |
I think we established that we don't need the changes in this PR for wasm support, so I'll close this |
The part that makes it wasm-compatible (turns a non- |
depends on #71
Make the futures of the trait wasm-compatible
This uses
async_trait
crate, but the function signatures remain largely untouched...change is from
to
So I think it's not that big of a change