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

Mutex::blocking_lock_owned #5109

Closed
smessmer opened this issue Oct 16, 2022 · 2 comments · Fixed by #5130
Closed

Mutex::blocking_lock_owned #5109

smessmer opened this issue Oct 16, 2022 · 2 comments · Fixed by #5130
Labels
A-tokio Area: The main tokio crate C-feature-request Category: A feature request. M-sync Module: tokio/sync

Comments

@smessmer
Copy link
Contributor

smessmer commented Oct 16, 2022

There is Mutex::try_lock_owned and Mutex::lock_owned, but I wasn't able to find a Mutex::blocking_lock_owned. Is there any specific reason for this omission?

Or is there a way to get the same behavior using the existing API somehow?

@smessmer smessmer added A-tokio Area: The main tokio crate C-feature-request Category: A feature request. labels Oct 16, 2022
@smessmer
Copy link
Contributor Author

smessmer commented Oct 16, 2022

Looking at the implementation of blocking_lock, it's just a future::block_on(Mutex::lock), so I guess that answers my second question, I can easily get around the limitation by doing a call to block_on(Mutex::lock_owned).

edit: Ok not that easy since tokio::runtime::block_on is private

@Darksonn Darksonn added the M-sync Module: tokio/sync label Oct 18, 2022
@Darksonn
Copy link
Contributor

I wouldn't mind adding this.

You can implement it yourself by storing a tokio::runtime::Handle to the runtime and calling Handle::block_on.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-tokio Area: The main tokio crate C-feature-request Category: A feature request. M-sync Module: tokio/sync
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants