async map functions for tokio::sync::RwLock #4305
Labels
A-tokio
Area: The main tokio crate
C-feature-request
Category: A feature request.
M-sync
Module: tokio/sync
Is your feature request related to a problem? Please describe.
It's currently not possible to use async code in
tokio::sync::RwLock(Read|Write)Guard::map
.Describe the solution you'd like
Additional
.map
methods that accept mapping closures that return a future, looking something likeDescribe alternatives you've considered
The owning variants of the guards could be used to solve my particular case, but doing so introduces significant complexity to reasoning about the code, since it means that inner locks can outlive outer locks.
Additional context
I'm trying to solve a problem similar to the one described in this reddit thread, where I have an outer
RwLock
to an object containing aVec
of innerRwLock
s, and I need make a function that returns an object that derefs to data inside one of the inner locks without causing lifetime problems. The Ideal approach in my mind would be to solve the problem withRwLock(Read|Write)Guard::map
, but that doesn't work because I need to use async code inside the map invocation. To describe it in pseudocode, I'm trying to do something likeIn other words, I need a a way to get a
RwLockReadGuard<RwLockReadGuard<U>>
The text was updated successfully, but these errors were encountered: