Conversation
|
Here is an example of some code that currently compiles and works correctly, but no longer compiles with this PR: #[component]
pub fn App() -> impl IntoView {
#[derive(Debug, Deserialize, Serialize)]
struct SomeData {
value: i32,
// imagine there are other fields here that are expensive to clone
}
// load the posts
let resource1 = Resource::new(|| (), |_| async { SomeData { value: 13 } });
let resource2 = Resource::new(|| (), |_| async { SomeData { value: 42 } });
let view = move || {
Suspend::new(async move {
let value_a = resource1.by_ref();
let value_b = resource2.by_ref();
let (value_a, value_b) =
futures::future::join(value_a, value_b).await;
value_a.value + value_b.value
})
};
view! { <Suspense>{view}</Suspense> }
}Specifically, this is because Now that I've had a chance to look at it in a little more detail, I think this is probably the primary reason I used an async lock here in the first place: less so that it can be read from without blocking, and more so that the read guard can be held across an await without needing to clone the inner value. |
|
Right. Yeah, that makes sense. I tried to do this and ran into issues since it naturally means modifying |
Right, what do you think about keeping parking_lot instead then? It allows send guards and is a much more common dependency than |
|
Sure... Looks like |
This refactors state management in
ArcAsyncDerivedto reduce the amount of separate locks.This also replaces the
AsyncRwLockfrom theasync_locklibrary with a normal rwlock.