-
-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use wasm-compatible sleep if compiled for wasm32 (#92)
- Loading branch information
Showing
11 changed files
with
108 additions
and
30 deletions.
There are no files selected for viewing
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 |
---|---|---|
@@ -1,16 +1,21 @@ | ||
use anyhow::Result; | ||
use backon::BlockingRetryable; | ||
use backon::ExponentialBuilder; | ||
|
||
// For more examples, please see: https://docs.rs/backon/#examples | ||
|
||
fn fetch() -> Result<String> { | ||
Ok("hello, world!".to_string()) | ||
} | ||
|
||
// this example does not run on wasm32-unknown-unknown | ||
#[cfg(not(target_arch = "wasm32"))] | ||
fn main() -> Result<()> { | ||
let content = fetch.retry(&ExponentialBuilder::default()).call()?; | ||
use backon::BlockingRetryable; | ||
|
||
let content = fetch.retry(&backon::ExponentialBuilder::default()).call()?; | ||
println!("fetch succeeded: {}", content); | ||
|
||
Ok(()) | ||
} | ||
|
||
#[cfg(target_arch = "wasm32")] | ||
fn main() {} |
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 |
---|---|---|
@@ -1,15 +1,18 @@ | ||
use anyhow::Result; | ||
use backon::BlockingRetryable; | ||
use backon::ExponentialBuilder; | ||
|
||
// For more examples, please see: https://docs.rs/backon/#examples | ||
|
||
fn main() -> Result<()> { | ||
// this example does not run on wasm32-unknown-unknown | ||
#[cfg(not(target_arch = "wasm32"))] | ||
fn main() -> anyhow::Result<()> { | ||
use backon::BlockingRetryable; | ||
|
||
let var = 42; | ||
// `f` can use input variables | ||
let f = || Ok::<u32, anyhow::Error>(var); | ||
let result = f.retry(&ExponentialBuilder::default()).call()?; | ||
let result = f.retry(&backon::ExponentialBuilder::default()).call()?; | ||
println!("var = {result}"); | ||
|
||
Ok(()) | ||
} | ||
|
||
#[cfg(target_arch = "wasm32")] | ||
fn main() {} |
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 |
---|---|---|
@@ -1,20 +1,24 @@ | ||
use anyhow::Result; | ||
use backon::ExponentialBuilder; | ||
use backon::Retryable; | ||
use sqlx::sqlite::SqlitePoolOptions; | ||
// For more examples, please see: https://docs.rs/backon/#examples | ||
|
||
// this example does not run on wasm32-unknown-unknown | ||
#[cfg(not(target_arch = "wasm32"))] | ||
#[tokio::main] | ||
async fn main() -> Result<()> { | ||
let pool = SqlitePoolOptions::new() | ||
async fn main() -> anyhow::Result<()> { | ||
use backon::Retryable; | ||
|
||
let pool = sqlx::sqlite::SqlitePoolOptions::new() | ||
.max_connections(5) | ||
.connect("sqlite::memory:") | ||
.await?; | ||
|
||
let row: (i64,) = (|| sqlx::query_as("SELECT $1").bind(150_i64).fetch_one(&pool)) | ||
.retry(&ExponentialBuilder::default()) | ||
.retry(&backon::ExponentialBuilder::default()) | ||
.await?; | ||
|
||
assert_eq!(row.0, 150); | ||
|
||
Ok(()) | ||
} | ||
|
||
#[cfg(target_arch = "wasm32")] | ||
fn main() {} |
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