Skip to content

Transaction

The commit coordinator: it runs a program as one commit of the store, and joins nested commits to the one already running. run opens a native transaction with Store.transaction, and inside it every write, such as a log append or a write a host enlists, runs as a step through operation, and every read through step, one at a time, so that a read never interleaves with writes the store has staged. A write that fails fails the whole commit, even when its caller catches the failure, and once its program ends the commit closes and rejects late writes. Everything built over one store shares one coordinator, from Log.layer, so their writes join one commit.

Since v0.2.0

Runs program so that every write through operation in it, appends included, fails with WriteForbidden, giving reason: for code that may update stores in the commit but must not append to its logs, such as a journal’s projections.

Signature

declare const withoutAppends: <A, E, R>(
program: Effect.Effect<A, E, R>,
reason: string
) => Effect.Effect<A, E, Exclude<R, Forbidden>>

Source

Since v0.2.0

Construct a transaction coordinator over host storage. Each acquisition owns its commits: a commit one coordinator opened cannot be joined through another.

Signature

declare const make: Effect.Effect<
{
readonly run: <A, E, R>(program: Effect.Effect<A, E, R>) => Effect.Effect<A, E | Error, Remaining<R>>
readonly operation: <A, E, R>(program: Effect.Effect<A, E, R>) => Effect.Effect<A, E | Error, Remaining<R>>
readonly step: <A, E, R>(program: Effect.Effect<A, E, R>) => Effect.Effect<A, E, R>
},
never,
Store.Store
>

Source

Since v0.2.0

A write in the commit had failed, though its caller caught the failure, so the commit rolls back; later writes in it fail with this too. cause is the first failure.

Signature

declare class Aborted

Source

Since v0.2.0

The commit had ended when a write or a nested commit tried to use it, such as from a fiber that outlived it.

Signature

declare class Closed

Source

Since v0.2.0

A commit’s storage work began a step while another fiber’s step was running. A commit runs its reads and writes one at a time, so await each before the next; concurrent work in one commit is a defect of the program that started it, raised as a defect and aborting the commit.

Signature

declare class Concurrent

Source

Since v0.2.0

What running a commit can fail with: storage’s errors and uncertain outcomes, and the coordinator’s own errors.

Signature

type Error = StoreError.StoreError | Store.CommitUncertain | Aborted | Closed | Foreign | WriteForbidden

Source

Since v0.2.0

A write reached a commit it does not belong to: one another coordinator opened, a native transaction no coordinator opened, or an entry of another log or commit, where a caller checks what it is given against its commit.

Signature

declare class Foreign

Source

Since v0.2.0

A write was attempted where writes are forbidden, such as by code that may update stores but not append; reason says which.

Signature

declare class WriteForbidden

Source

Since v0.2.0

Provide one transaction coordinator over host storage.

Signature

declare const layer: Layer.Layer<Transaction, never, Store.Store>

Source

Since v0.2.0

What a program run as a commit still requires once the commit provides its scope and Store.Transaction.

Signature

type Remaining<R> = Exclude<Exclude<R, Scope.Scope>, Store.Transaction>

Source

Since v0.2.0

The commit coordinator of one store, shared by Log and whatever a host builds over it, such as a journal of facts. make builds it over Store.Store, and layer provides it.

Signature

declare class Transaction

Source

Since v0.2.0