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

Semaphore doc final cleanup #6050

Merged
merged 5 commits into from
Oct 5, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Minor cleanups
  • Loading branch information
Darksonn committed Oct 5, 2023
commit cb7f1eaa884ad0195e750b14b539ed878714021d
14 changes: 7 additions & 7 deletions tokio/src/sync/semaphore.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ use std::sync::Arc;
/// }
/// ```
///
/// ## Limit the number of simultaneously opened files in your program.
/// ## Limit the number of simultaneously opened files in your program
///
/// Most operating systems have limits on the number of open file
/// handles. Even in systems without explicit limits, resource constraints
Expand Down Expand Up @@ -76,7 +76,7 @@ use std::sync::Arc;
/// }
/// ```
///
/// ## Limit the number of incoming requests being handled at the same time.
/// ## Limit the number of incoming requests being handled at the same time
///
/// Similar to limiting the number of simultaneously opened files, network handles
/// are a limited resource. Allowing an unbounded amount of requests to be processed
Expand Down Expand Up @@ -137,7 +137,6 @@ use std::sync::Arc;
/// We can leverage a semaphore with a single permit to address this challenge.
///
/// ```
/// use tokio::sync::Semaphore;
/// # use tokio::sync::Mutex;
/// # use std::collections::BTreeMap;
/// # struct Database {
Expand All @@ -164,6 +163,7 @@ use std::sync::Arc;
/// # *self.map.lock().await.get(key).unwrap()
/// # }
/// # }
/// use tokio::sync::Semaphore;
///
/// // Initialize a static semaphore with only one permit, which is used to
/// // prevent test_insert and test_update from running in parallel.
Expand All @@ -173,7 +173,7 @@ use std::sync::Arc;
/// static DB: Database = Database::setup();
///
/// #[tokio::test]
/// # async fn fake_test() {}
/// # async fn fake_test_insert() {}
/// async fn test_insert() {
/// // Acquire permit before proceeding. Since the semaphore has only one permit,
/// // the test will wait if the permit is already acquired by other tests.
Expand All @@ -196,7 +196,7 @@ use std::sync::Arc;
/// }
///
/// #[tokio::test]
/// # async fn fake_test() {}
/// # async fn fake_test_update() {}
/// async fn test_update() {
/// // Acquire permit before proceeding. Since the semaphore has only one permit,
/// // the test will wait if the permit is already acquired by other tests.
Expand All @@ -221,12 +221,12 @@ use std::sync::Arc;
/// }
///
/// #[tokio::test]
/// # async fn fake_test() {}
/// # async fn fake_test_others() {}
/// async fn test_others() {
/// // This test can run in parallel with test_insert and test_update,
/// // so it does not use PERMIT.
/// }
/// # #[tokio::main]
/// # #[tokio::main(flavor = "current_thread")]
/// # async fn main() {
/// # test_insert().await;
/// # test_update().await;
Expand Down