UNPKG

@arturwojnar/hermes-postgresql

Version:

Production-Ready TypeScript Outbox Pattern for PostgreSQL

26 lines 753 B
import { CancellationPromise } from '@arturwojnar/hermes'; import { createSimpleQueue } from './createSimpleQueue.js'; const createAsyncOpsQueue = () => { const _ops = createSimpleQueue(); let opInProgress = CancellationPromise.resolved(); const queue = (op) => { _ops.queue(op); return op; }; const waitFor = async (op) => { if (opInProgress.isPending) { await opInProgress; } opInProgress = new CancellationPromise(); try { await op(); _ops.remove(op); } finally { opInProgress.resolve(); } }; return { queue, waitFor }; }; export { createAsyncOpsQueue }; //# sourceMappingURL=createAsyncOpsQueue.js.map