-
Notifications
You must be signed in to change notification settings - Fork 405
Closed
Labels
bugSomething isn't workingSomething isn't working
Description
Describe the bug
The retry mechanism get_with_retry
does not work on the browser (wasm32-unknown-unknown
) and fails with the following error:
error output:
panicked at library/std/src/sys/pal/wasm/../unsupported/time.rs:31:9:
time not implemented on this platform
The reason is that WebAssembly in browsers doesn’t have direct support for timing mechanisms like std::time::Instant
or std::thread::sleep
.
To Reproduce
Can run the tests on this repo for sync
: https://github.com/darioAnongba/bdk-wasm
Expected behavior
Build environment
- BDK tag/commit:
- bdk_wallet = { version = "1.0.0-beta.5" }
- bdk_esplora = { version = "0.19.0", features = ["async-https"] }
- OS+version: macOS 14.7
- Rust/Cargo version: 1.79
- Rust/Cargo target: wasm32-unknown-unknown
Additional context
Using gloo-timers
instead ?
use gloo_timers::future::sleep;
use std::time::Duration;
const BASE_BACKOFF_MILLIS: u64 = 100;
async fn get_with_retry(&self, url: &str) -> Result<Response, Error> {
let mut delay = BASE_BACKOFF_MILLIS;
let mut attempts = 0;
loop {
match self.client.get(url).send().await {
Ok(resp) if attempts < self.max_retries && is_status_retryable(resp.status()) => {
sleep(Duration::from_millis(delay)).await;
attempts += 1;
delay *= 2;
}
Ok(resp) => return Ok(resp),
Err(e) => return Err(e), // Handle error if send fails
}
}
}
or 2 functions
#[cfg(not(target_arch = "wasm32"))]
async fn get_with_retry(...) {
// Original retry logic with task::sleep
}
#[cfg(target_arch = "wasm32")]
async fn get_with_retry(...) {
// Non-retrying version for WebAssembly
}
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't working
Type
Projects
Status
Done