fabulous-dev / Fabulous

Declarative UI framework for cross-platform mobile & desktop apps, using MVU and F# functional programming
https://fabulous.dev
Apache License 2.0
1.13k stars 122 forks source link

Don't eat exceptions thrown in MVU functions #956

Closed TimLariviere closed 1 year ago

TimLariviere commented 2 years ago

This PR introduces a LogException function in the Logger available inside the Program. It also rethrows exceptions after calling LogException.

We use a Mailbox to process new messages and it makes it hard to rethrow an exception with the proper stacktrace. I noticed Elmish moved away from MailboxProcessor, maybe we need something similar.

edgarfgp commented 2 years ago

Is there any benefit apart from rethrow using a non MailBoxProcessor approach ?

Will the possible change still allow us to add support to run multiple programs in the future ?

TimLariviere commented 2 years ago

Is there any benefit apart from rethrow using a non MailBoxProcessor approach ?

Not sure. Removing Mailbox would also let us avoid switching threads all the time. We would be able to run by default on the main thread and let Cmd decide to move to another thread or not. eg. Cmd.MainThread.ofMsg (UI thread) vs Cmd.ofMsg (another thread)

I feel this would be a cleaner approach compared to today.

Will the possible change still allow us to add support to run multiple programs in the future ?

Yes. In v1, we had a singleton dispatch mainly for LiveUpdate. So here we would have an instance function that dispatches only to the associated runner. You can still have multiple runners in a same app.

TimLariviere commented 2 years ago

I replaced the mailbox with a concurrent queue and a while loop. Seems to be working fine, but I still need to dogfood this change before merging it

TimLariviere commented 1 year ago

This PR is quite an important change with potential breaking behavior. I will merge it to v2.1-preview branch