-
-
Notifications
You must be signed in to change notification settings - Fork 811
WIP: Refactor ArcAsyncDerived #4409
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
base: main
Are you sure you want to change the base?
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.