-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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 examples are lacking #5933
Comments
May be too much for docs, but this is where I hit needing semaphore. Thanks again for help. Docker Compose in Test Example
|
Yeah, that's a great starting point for the third example, but the examples generally need to be shorter. |
Ya, cutting out the docker part would be good. But I spent a lot of time troubleshooting |
I'm green to Tokio (and Rust in general) -- but I'll give this a shot. |
@alexanderkirilin Make sure you don't submit the same example as in #5939. We don't want duplicate work. |
@alexanderkirilin Which example did you intend to add? |
@Darksonn Hi, sorry for the delay. I made a PR for a spin on the second one (Limit number of incoming requests being handled at the same time, using acquire_owned. (Similar to current second example, but the title actually explains what the example does, rather than mentioning that it uses acquire_owned); here: #5956 |
The only missing example from my list is preventing several tests from running at the same time. Anyone wants to take it? |
I'd like to take the last example. Can you provide more details about it? I'm curious, under what circumstances would we want to prevent several tests from running simultaneously? @Darksonn |
For example, maybe the tests are talking to the same database, so you want to prevent them from interfering with each other. |
I've drafted the example below and would appreciate any feedback on how to improve it, @Darksonn.
|
It looks fine, go ahead and post a PR. There are some minor details I'd change, but it's easier for me to mention them using the PR interface, since it makes it easy to point at specific lines.
You can just say that using two different keys is preferable when possible, but there are cases where it is difficult to separate them like that, and in those cases you can use this strategy. |
can you give a look? @Darksonn |
Thanks everyone! The examples have been added. As a preview, check out the new documentation: https://deploy-preview-6050--tokio-rs.netlify.app/tokio/sync/struct.semaphore |
This is absolutely wonderful. Amazing |
Currently, the documentation for
tokio::sync::Semaphore
has two top-level examples with these titles:Semaphore::acquire_owned
to move permits across tasks.These examples aren't great. I would prefer to instead have examples that show common use-cases of semaphores. Here are some examples I thought of:
acquire_owned
. (Similar to current second example, but the title actually explains what the example does, rather than mentioning that it usesacquire_owned
.)const_new
.)add_permits
andSemaphorePermit::forget
.This is a good first issue. Contact me for mentoring. I'm also open to other examples than the ones I mentioned; they're just my ideas. It's also perfectly okay to submit a PR that only partially resolves this issue, e.g. by adding just one example.
The text was updated successfully, but these errors were encountered: