Choose between the return value of an IO action and an STM operation, depending on which is available first.
runs the IO action
runOrElse io stm
io. If its result is
itself returns, then that value is
used as the function's return value. If not, the STM operation
stm is attempted. Then, whichever of
value is then available first is returned from
a preference to that of
io if both are available.
reverses this priority.
It can happen that
stm is never attempted. If it is, however, its
result is used as return value only if it is available before
io. Note that in that case, a long-running
io will keep
running until completed, even if
has already returned
with the result of
stm. A future version will probably kill off
io thread if its value is not needed (i.e. if that of
value is used), but that is not currently the case.
A version of
runOrElse that prefers the STM operation to the IO
action. In this case, the IO action is always run, but its value
is only used if the return value of the STM operation is not
available when the function returns.
The same caveat regarding long-running IO operations as for
runOrElse also applies here.