Concurrency and the elm architecture

I don’t think this is a concurrency problem, but more a misunderstanding of how views work in Elm. Views will only be updated when the model changes and the browsers triggers a redraw. In most cases, after the model is updated the view will be recalculated somewhere within the next 1/60th of a second. The issue that you see in your example comes when the timer fires and the user also clicks the button inside of that window. Your view ends up using an old model to compute the update. The simplest way to mitigate this is to never rely on the model in the view function to calculate updates. Instead create an increment action and do the calculation in your update function. I have forked your example to clarify what I mean.

3 Likes