transaction

tcmts.server.transaction · #gcgsagk3 · term · runs on the server

uses #tcm/host (transaction)

Run fn as one transaction over every table: all its writes happen, or, if it throws, none do. While it runs, other requests' table calls wait, so none sees its uncommitted rows or writes in between. Jobs it enqueues are queued when it commits, and dropped if it rolls back. A transaction inside one is a savepoint. Keep it short (it holds the store), and don't await anything inside that itself waits for a table.

import { transaction as hostTransaction } from "#tcm/host";

export function transaction<R>(fn: () => R | Promise<R>): Promise<R> {
  return hostTransaction(fn);
}

used by