-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Fix Ensure the appState is loaded only once and GetAppState always returns #3193
Conversation
/// <param name="driver">The suspension driver.</param> | ||
/// <returns>A completed observable.</returns> | ||
private static IObservable<Unit> EnsureLoadAppState(this ISuspensionHost item, ISuspensionDriver? driver = null) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can possibly use the Interlocked.Exchange(ref initFunction, null)?.Invoke()
then store a Action or Func with the init logic. This is thread safe as well but avoids the lock
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh wow, it took me a while, I have never used Interlocked
, but I understand and this is clever. Commit will be coming right up
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like you got the idea correctly.
.Cast<T>(); | ||
if (item.AppState is null) | ||
{ | ||
item.EnsureLoadAppState(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This would be a threading issue. If you use the interlock approach and always call the method could avoid that
Using Interlocked.Exchange to prevent dead lock and Threading issues.
I've got to sleep but thanks for this |
Looks like Maui has changed so I'll have to fix those build errors. They are unrelated to your stuff |
Figured that out, but thanks for letting me know anyway |
I'm a bit confused, loading the AppState may occur more than once during the lifecycle of an app, if an app is suspended then resumed on mobile platforms - why would we want to only load it once? |
I have never developed on mobile platforms, but the state shouldn't be expected to change in storage while suspended no? So the initially loaded one should be still actual. If I am wrong, then this needs to be done otherwise. |
This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
fixes #3192