Class Transaction
- Namespace
- SodaFlow
- Assembly
- SodaFlow.dll
A class for managing transactions.
[PublicAPI]
public static class Transaction
- Inheritance
-
Transaction
- Inherited Members
Remarks
The process runs only one transaction at a time, on all of its threads. A thread that starts a transaction waits until the transaction on a different thread ends. This is deliberate. It makes a transaction atomic for each other thread, thus no code sees the graph in the middle of an update. The sequence of the updates also stays deterministic, and the number of threads that push values in makes no difference. Thus, code on more than one thread can use SodaFlow with no more synchronization of its own.
The cost of that guarantee is that the transaction keeps the lock for all of its operation. That includes each listener callback that it fires and each Post(Action) action that it queues, which run while the transaction closes, with the lock held. While a callback runs, no other thread can start a transaction. Thus, a callback must return quickly. Give work that takes a long time, and work that blocks, to a different thread, and do not do it inline. A callback that waits on a thread that tries to start a transaction causes a deadlock.
A nested transaction has no cost. A transaction that starts while one is open on the same thread becomes part of the open transaction, and does not get the lock again. Thus, the primitives that open their own transactions add no cost in Run<T>(Func<T>) or RunVoid(Action).
Methods
- IsActive()
Gives true when there is a current transaction.
- OnStart(Action)
Adds an action that runs at the start of each transaction.
- Post(Action)
Runs an action after the current transaction closes or immediately if there is no current transaction.
- Post(Action, Action<Exception>)
Runs an action after the current transaction closes, or immediately if there is no current transaction. Runs
onFailurewhere that action does not run or does not complete.
- RunVoid(Action)
Runs the given action in one transaction.
- Run<T>(Func<T>)
Runs the given function in one transaction.