Arke.Hook.Deferred (Arke v0.9.0-rc.0)

Copy Markdown View Source

Process-local queues for the callbacks deferred to the transaction boundary.

after_commit and after_rollback entries queue while a transaction is open and run after the OUTERMOST commit or rollback, so a write nested in a larger transaction gets its slot from the outcome that actually decided it. When no transaction is open, "outermost" degrades to "pipeline success or failure" and the entries run immediately, so arkes opted out of the transaction keep both slots.

begin/0/finish/0 bracket every transaction the write pipeline opens; whichever of commit/0/rollback/1 fires empties both queues.

Summary

Functions

Runs the queued after_commit entries oldest first — only when no transaction is open. Entries are expected to isolate their own failures (Arke.Hook.Pipeline.run_isolated/3).

Runs the queued after_rollback entries with the failure reason — only when no transaction is open. Compensators undo in reverse order of the writes that queued them, so the queue is drained newest first.

Functions

begin()

@spec begin() :: :ok

commit()

@spec commit() :: :ok

Runs the queued after_commit entries oldest first — only when no transaction is open. Entries are expected to isolate their own failures (Arke.Hook.Pipeline.run_isolated/3).

depth()

@spec depth() :: non_neg_integer()

finish()

@spec finish() :: :ok

on_commit(fun)

@spec on_commit((-> any())) :: :ok

on_rollback(fun)

@spec on_rollback((any() -> any())) :: :ok

rollback(error)

@spec rollback(any()) :: :ok

Runs the queued after_rollback entries with the failure reason — only when no transaction is open. Compensators undo in reverse order of the writes that queued them, so the queue is drained newest first.