Managing side effects inside MailboxProcessor and asynchronous workflows
We may have been tempted to use a MailboxProcessor
instantiation wrapped within an asynchronous workflow. It is not recommended to have this overly complex wrapper as MailboxProcessor already has its own asynchronous context.
This is also applied to interoperability with the UI thread as well as asynchronous context should not be mixed with the UI thread directly. Mixing the UI thread with asynchronous contexts will yield unpredictable results.
If we must use Windows forms, it is best to have asynchronous workflow and the UI coded in F#. Using WPF, we can use WPF Dispatcher to ensure we will not have cross-thread violation.
On managing side effects, using MailboxProcessor
to do side effects activity must be handled carefully.
Consider these scenarios and the reasons:
Upon receiving the messages inside the delegate parameter of a
MailboxProcessor
instantiation, we have calls to get web content asynchronously. These multiple...