MCPcopy Create free account
hub / github.com/Effect-TS/effect / makeAfterCommit

Function makeAfterCommit

packages/effect/src/sql/SqlClient.ts:654–671  ·  view source on GitHub ↗
(transactionService: Context.Key<any, any>)

Source from the content-addressed store, hash-verified

652
653const makeAfterCommit =
654 (transactionService: Context.Key<any, any>) =>
655 <R>(effect: Effect.Effect<void, never, R>): Effect.Effect<void, never, R> =>
656 Effect.withFiber((fiber) => {
657 const transaction = Context.getOrUndefined(fiber.context, transactionService)
658 const buffer = transaction && afterCommitBuffers.get(transaction)
659 // Outside a transaction, or in one that doesn't buffer callbacks.
660 if (buffer === undefined) {
661 return runAfterCommit(effect)
662 }
663 if (hasEnded(buffer)) {
664 return Effect.die(new Error("SqlClient.afterCommit: the transaction has already ended"))
665 }
666 // Runs later with the services in scope now, without the transaction.
667 buffer.callbacks.push(
668 Effect.provideContext(effect, Context.omit(transactionService)(fiber.context) as Context.Context<R>)
669 )
670 return Effect.void
671 })
672
673/**
674 * Builds a transaction wrapper that begins top-level transactions, uses

Callers 2

SqlClient.tsFile · 0.85
makeWithTransactionFunction · 0.85

Calls 5

runAfterCommitFunction · 0.85
hasEndedFunction · 0.85
getMethod · 0.65
pushMethod · 0.65
omitMethod · 0.65

Tested by

no test coverage detected