Search code examples
haskelleventsconcurrencystm

STM and outgoing IO


If I am inside a STM whose transaction fail, and I retry as part of the normal control flow (no STM collision etc..), I might want to indicate to someone outside a way to take corrective action.

If it's purely 'outgoing', then my STM can still be replayed purely.

How might I perform outgoing IO from a STM retry ?

Has anyone encountered this ? How evil is this ?


Solution

  • If you are sure that the performed IO does not affect the invariants of STM, you can use unsafeIOToSTM. Use it with great care, as all the unsafe stuff.

    I do, however, wonder if you really need that. It's impossible to tell from the question. If you can, you should avoid it.