Txn

final case class Txn[+M <: TxnMode, +A](step: TxnStep[M, A])

Embedded language for safely working with(in) an IndexedDB transaction.

This is necessary because whilst all the transaction methods are async, any other type of asynchronicity is not supported and will result in IndexedDB automatically committing and closing the transaction, in which case, further interaction with the transaction will result in a runtime error.

Therefore, returning AsyncCallback from within transactions is dangerous because it allows composition of both kinds of asynchronicity. To avoid this, we use this embedded language and don't publicly expose its interpretation/translation to AsyncCallback. From the call-site's point of view, a Txn[A] is completely opaque.

This also has a nice side-effect of ensuring that transaction completion is always awaited because we do it in the transaction functions right after interpretation. Otherwise, the call-sites would always need to remember to do it if live transaction access were exposed.

Type parameters:
A

The return type.

Companion:
object
trait Serializable
trait Product
trait Equals
class Object
trait Matchable
class Any
Txn[M, A]

Value members

Concrete methods

def >>[N <: TxnMode, B](f: Txn[N, B])(implicit m: Merge[M, N]): Txn[Mode, B]
Implicitly added by InvariantOps
def flatMap[N <: TxnMode, B](f: A => Txn[N, B])(implicit m: Merge[M, N]): Txn[Mode, B]
Implicitly added by InvariantOps
def map[B](f: A => B): Txn[M, B]
@inline
def unless(cond: Boolean)(implicit ev: TxnStep[RO, Option[Nothing]] => Txn[M, Option[Nothing]]): Txn[M, Option[A]]
Implicitly added by InvariantOps
@inline
def unless_(cond: Boolean)(implicit ev: TxnStep[RO, Unit] => Txn[M, Unit]): Txn[M, Unit]
Implicitly added by InvariantOps
def void: Txn[M, Unit]
def when(cond: Boolean)(implicit ev: TxnStep[RO, Option[Nothing]] => Txn[M, Option[Nothing]]): Txn[M, Option[A]]
Implicitly added by InvariantOps
def when_(cond: Boolean)(implicit ev: TxnStep[RO, Unit] => Txn[M, Unit]): Txn[M, Unit]
Implicitly added by InvariantOps

Inherited methods

def productElementNames: Iterator[String]
Inherited from:
Product
def productIterator: Iterator[Any]
Inherited from:
Product