Skip to content
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

docs: document custom Sleeper impl #147

Merged
merged 6 commits into from
Sep 5, 2024

Conversation

SteveLauC
Copy link
Contributor

What does this PR do

Adds an example for user-provided sleeper implementation.

Closes #129

backon/src/lib.rs Outdated Show resolved Hide resolved
//!
//! - `tokio-sleep`: Utilizes [`TokioSleeper`] within a Tokio context in non-wasm32 environments.
//! - `gloo-timers-sleep`: Utilizes [`GlooTimersSleep`] to pause in wasm32 environments.
//! Currently, BackON has 2 built-in `Sleeper` implementations for different environments,
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be 3, we have std-blocking-sleep for blocking context.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added the BlockingSleeper to the table.

//! ```rust,ignore
//! use std::time::Duration;
//! use backon::Sleeper;
//! use monoio::time::sleep;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't want to use Monoio as an example here. Let's just implement a function that prints "Hello, World!" and then returns Ready

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

//!
//! ## The empty `Sleeper`
//!
//! If neither feature is enabled nor a custom implementation is provided, BackON will fallback to the empty sleeper. This will cause a panic in the `debug` profile and do nothing in the `release` profile.
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is out-of-date now. We will raise a build error now.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated

@Xuanwo
Copy link
Owner

Xuanwo commented Sep 4, 2024

Would you like to also provide an real example in docs::examples?

@SteveLauC
Copy link
Contributor Author

Would you like to also provide an real example in docs::examples?

Sure, will address the feedback tomorrow:)

@SteveLauC
Copy link
Contributor Author

Would you like to also provide an real example in docs::examples?

Done

@@ -31,16 +31,53 @@
//!
//! # Sleep
//!
//! Retry in BackON requires an implementation for sleeping. BackON will accept a [`Sleeper`] to pause for a specified duration.
//! Retry in BackON requires an implementation for sleeping, such an implementation
//! is called a Sleeper, it will implement [`Sleeper`] or [`BlockingSleeper`] depending
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

such an implementation is called a Sleeper, it will implement [Sleeper] or [BlockingSleeper] depending on if it is going to be used in an asynchronous context.

I try to differentiate "Sleeper" from "`Sleeper`" (quoted with backticks), the former is a general concept, which can be a "`Sleeper`" or "`BlockingSleeper`", while the later is just the async Sleeper trait.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense.

Copy link
Owner

@Xuanwo Xuanwo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks a lot!

@Xuanwo Xuanwo merged commit b3ca11e into Xuanwo:main Sep 5, 2024
7 checks passed
@SteveLauC SteveLauC deleted the docs/custom_sleeper branch September 5, 2024 04:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add an example for user provided sleeper
2 participants