I'm making a wasm app with web_sys and I'm trying to use IndexedDB to store some data, but I can't figure out how to do anything because everything requires async, which in turn requires me to change every function in my codebase where I use IndexedDB to also be async, and I'm not doing that. None of the IndexedDB-related crates that I've found appear to help either. Can someone please provide a minimal example of how to use it? Writing the main implementation in javascript and then using wasm_bindgen to create rust bindings is also ok, but I can't figure out how to do that either. Really all I need is a simple IndexedDb struct with new, get, and set functions.
#How to use IndexedDB in web_sys without running into the "colored functions" problem
4 messages · Page 1 of 1 (latest)
It is in general possible to write a block_on adapter that takes a future and blocks until it's done, so you can call async from sync. There are crates for this
In particular, which crate you want sort of depends on which runtime indexeddb expects you to be using. If it's tokio, you'll need that one (at which point you can construct a runtime and use it to block_on). The lightweight case would be the one in which you can just use pollster, but I have no idea whether it'll work
For reference, the tokio example:
let function_output = Runtime::new().unwrap().block_on(indexed_db_function());
```I think you can cache the runtime rather than keep making new one, too.
As for pollster:
```rs
let function_output = pollster::block_on(indexed_db_function());