transact
transact<
Value>(authority,fn):TransactResult<Value>
Runs fn, and applies everything it changed together or nothing at
all: trait writes, editTrait’s among them, spawns, destroys, events,
command results, text chat and the deliveries it sends. A throw, an
engine write a deployed room refused, or a fn that returns a promise
aborts it: nothing applies, the throw is logged, and it answers
{ isApplied: false, error }. Reads inside fn see its own writes; a
destroy is held until it applies, so the entity reads as alive until
then. A transact inside another joins it: its writes apply with the
outer one, and a failure inside throws TransactionAbortedError, which
aborts the outer one even where its fn catches it. A store kept
outside traits, a module’s map, a closure’s variable, a physics body’s
pending force, a joint, an attachment and control are outside it: the
verbs that keep state outside traits throw inside a transaction. As a
database’s transaction, and Unity’s EntityCommandBuffer, which applies
its changes together.
Type Parameters
Section titled “Type Parameters”| Type Parameter |
|---|
Value |
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
authority |
Authority |
fn |
() => Value extends PromiseLike<unknown> ? never : Value |
Returns
Section titled “Returns”TransactResult<Value>
Example
Section titled “Example”const placed = transact(step, () => { spendTreasury(step, 100); return placeBuilding(step, tile);});if (placed.isApplied) command.accept({ building: placed.value });else command.refuse("too-poor");