Atom swap eff documentation #1279
Replies: 2 comments
-
It is explicit throughout the documentatoin: [1] , [2], [3]. The assumption is nobody goes in to using Your point about side-effects in atoms is fair though. Not sure what I was thinking when I did that, I was probably thinking more about trying to have as much of the library work together as possible. I'll leave it for now, because maybe there was a point to this, but it doesn't smell right for sure. |
Beta Was this translation helpful? Give feedback.
-
Literally as I posted the above, I remembered. Atoms must, by defintion, have side-effects. They are changing the global state of the world. So, it makes sense that there's a declarative version of them that makes this explicit. They then work like Probably warnings need to be more focussed around idempotency and commutability than about not containing side-effects. |
Beta Was this translation helpful? Give feedback.
-
Atoms swap implementation uses optimistic locking.
I have tested, that in case of concurrent swaps the effect returned by
f
is run multiple times.Assuming this is supposed to happen, I find the summary should be more explicit:
If
f
may be called multiple times, then the returned effect will be called multiple times as well.And an effect encapsulates side-effects by definition.
So instead of only hinting that
f
should be side-effect free, it should tell, that returned side-effects will be run multiple times.I will contribute a PR, when the issue is clear.
Also, for me as an unexperienced effects user, the current behavior of
Atom.SwapEff
is not expected.I would have made the following mistake:
Concurrent calls to
DeleteFile
will eventually fail, because the file has already been deleted.Now that I know how
Atom.SwapEff
works, I would implement it so:Well, actually there is no point in using
SwapEff
here, so I would simplify to:Beta Was this translation helpful? Give feedback.
All reactions