UNPKG

inngest

Version:

Official SDK for Inngest.com. Inngest is the reliability layer for modern applications. Inngest combines durable execution, events, and queues into a zero-infra platform with built-in observability.

63 lines (61 loc) 1.54 kB
import { StepMode } from "../../types.js"; //#region src/components/execution/lazyOps.ts /** * Buffer for opcode-only sync ops (e.g. `DeferAdd`). These ops need to be * buffered until the next outbound wire message (e.g. checkpointing a * `step.run`). * * The engine owns shipping. This helper owns the buffer. */ var LazyOps = class { buffer = []; pushedIds = /* @__PURE__ */ new Set(); /** * Number of ops waiting to ship. */ get length() { return this.buffer.length; } /** * Whether an op with this hashed id has been pushed in this execution * (whether or not it has since been drained). */ hasId(id) { return this.pushedIds.has(id); } /** * Take ownership of buffered ops and clear the buffer. Callers ship them on * whichever wire message comes next. */ drain() { if (this.buffer.length === 0) return []; const ops = this.buffer; this.buffer = []; return ops; } /** * Buffer an op for later shipment. */ push(op) { this.buffer.push(op); this.pushedIds.add(op.id); } /** * Record that an id has been observed in this execution without buffering * an op for it. Used to consume a `priorDefers` replay match so that * subsequent encounters of the same id surface as duplicates. */ markSeen(id) { this.pushedIds.add(id); } }; /** * True when a step being registered is an opcode-only sync op (no local * handler, sync mode). */ function isLazyOp(opts, opId) { return !opts?.fn && opId.mode === StepMode.Sync; } //#endregion export { LazyOps, isLazyOp }; //# sourceMappingURL=lazyOps.js.map