The Author Online Book Forums are Moving

The Author Online Book Forums will soon redirect to Manning's liveBook and liveVideo. All book forum content will migrate to liveBook's discussion forum and all video forum content will migrate to liveVideo. Log in to liveBook or liveVideo with your Manning credentials to join the discussion!

Thank you for your engagement in the AoF over the years! We look forward to offering you a more enhanced forum experience.

jeffmad (5) [Avatar] Offline
in 6.5.3: Side effects in STM transactions

Text currently reads:

Agents can be used to facilitate such intended side effects. Consider the following pseudo code:


Clojure’s STM transactions hold all actions that need to be sent to agents until they succeed. In the pseudo code shown here, log-message and send-message-on-queue are actions that will be sent only when the transaction succeeds.


I had to read this a couple times to understand that Agents have unique properties when executed in a dosync compared to atoms, ref, and regular functions. They will be executed once and the result will be held until the commit. Even if the transaction is tried multiple times, the actions performed by send and send-off (side effects or not) only get performed once.

I thought about how to reword some of it and ended up with this:

By using an Agent in a transaction, one can generate side effects and be assured that the side effect causing actions are only sent once, even if the transaction is tried multiple times.
amitrathore (132) [Avatar] Offline
Re: wording in side effects in STM transactions CIA v5
Yup - got it. Updated to make the sentence clearer. Thanks!