-
-
Notifications
You must be signed in to change notification settings - Fork 69
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
Prepare for disappearance of withSyncDispatch #112
Comments
Re. 3: I don't see async being part of the problem. IIRC the problem was that when the message loop (including
At a high level, @et1975 can probably answer this better than I can. Hopefully fairly trivially, like with the change to |
Yes, you are correct. I only meant to suggest asynchronous computations as a common example of how a user might introduce multithreading into their application, but I forgot to explicitly say the part about there being an additional thread. I edited that part of my comment. Hopefully it is clear now. |
I think the solution might be to change Elmish.WPF/src/Elmish.WPF/Program.fs Lines 27 to 33 in 9a24da9
to let runElmish () =
program
|> Program.withSetState setState
|> Program.run
element.Dispatcher.Invoke runElmish If so, then we can make this change now. |
Synchronized/Serialized dispatch is not going away, but it's an implementation detail of the current dispatch loop. I'm removing it from the |
Great. Then we have nothing to worry about. Thanks @et1975 :) |
Elmish.WPF currenting uses
Elmish.Program.withSyncDispatch
hereElmish.WPF/src/Elmish.WPF/Program.fs
Line 32 in 5df8514
As I understand it, three goals are achieved with this code.
dispatch
callssetState
, which mutates UI state. That mutation must occur on the UI thread (otherwise anInvalidOperationException
will occur).dispatch
is not thread safe due to race conditions related to improper message processing. Executingdispatch
only on the UI thread avoids this issue.dispatch
(viasetState
) and the user (through the UI thread) can modify the state of the view. Even without usingwithSyncDispatch
, WPF would synchronously calldispatch
, which avoids "many" race conditions. However, it is also possible to calldispatch
on a different thread (such as within an asynchronous command), and this can cause a race condition as describe in detail by @cmeeren in Discussion: MVU architecture gives feedbak loop when UpdateSourceTrigger=PropertyChanged and update loop is sufficiently slow #40 (comment). By executingdispatch
on the UI thread, the mutation to the model reference bydispatch
and the mutation to the view state by the UI thread stay consistent.Are there any more goals that I missed?
The third one is the most complicated, so please do correct me if I said anything wrong.
In elmish/elmish#185 (comment), @et1975 says that
withSyncDispatch
will be removed in the next major release of Elmish.How will Elmish.WPF be modified to handle this change?
The text was updated successfully, but these errors were encountered: