toggle

fun toggle(defaultValue: Boolean = false): (DatasyncValue) -> TransactionOperation

Transaction function that atomically toggles the value of a boolean data node.

If the data node is not set it sets the defaultValue, if the data node has a non-boolean value it aborts the transaction. This function is expected to be passed to the DatasyncNode.runTransaction method.


inline fun <T : Any> toggle(ping: T, pong: T): (DatasyncValue) -> TransactionOperation

Transaction function that atomically toggles the value of a data node between 2 values ping and pong.

If the data node is not set it sets the ping value, if the data node has a value that is not of type T it aborts the transaction. This function is expected to be passed to the DatasyncNode.runTransaction method.