The description in Async-friendly RefCell that prevents borrow across await points was a misstatement of the problem.
I want to have something like:
struct Foo {
inner: SingleThreadedAsyncCell<Inner>
}
impl Foo {
pub async fn do_something(&self) {
self.inner.borrow().really_do_something().await;
}
pub async fn do_something_else(&self) {
self.inner.borrow_mut().really_do_something_else().await;
}
}
async fn do_many_somethings(f: &Foo) {
join!(f.do_something(), f.do_something_else(), f.do_something_else());
}
It should be safe to concurrently borrow and borrow_mut even while waiting since the interior is written to handle concurrent mut while suspended.
I want to make sure that the borrow is held while polling but released while waiting. That being said, I’m not tied to this specific RefCell-like API. If there’s an alternate way of framing a solution I’m open to hearing ideas.
Or in this case do I just fall back to storing all the mutable state behind an UnsafeCell?