The problem comes from the fact that the file i want to process is >4GB, so I can't just read it into memory and pass it down as an Uint8Array. Instead I want to process it chunk-wise.
The JS File API provides the ability to get a slice of a file as an ArrayBuffer, but this is a Promise based API so asynchronous.
So I already understand the following:
- I can use the wasm_bindgen_futures crate to convert the JS Promise into a Rust Future.
However at this point I'm confused as most of the guides on the internet expect you'll be using tokio/async-std to deal with futures.
wasm_bindgen_futures provides a
then which then calls back into rust and resumes that call?
However the problem is that that function only works on
Future<()> which makes sense as I can't see how you'd wait for a result using that mechanism.
The problem here is that I actually want to feed the data read from this file into the Gimli crate's Dwarf.load method. This method expects to be passed a
FnMut which is can call whenever it a particular section's data.
I can't see how it'd be possible for me to write a callback function that can then await the Future/Promise which reads the data before passing it back to Gimli as this requires maintaining Gimli's call stack upto that point.
If this weren't in WASM I think I could just have Gimli running in a thread which then blocks on a mutex until the data is ready, but currently WASM has no threading support either.
So ultimately think my question here is, do i have to rewrite/modify gimli to be entirely async in order to be able to use it from this context? Or am i missing something?