| /** | |
| * Durable timers for workflow sleeps. | |
| * | |
| * `make` creates a `DurableClock` with a name, duration, and deferred wake-up | |
| * signal. `sleep` ignores zero durations, runs short sleeps through an | |
| * in-memory activity, and schedules longer sleeps through the `WorkflowEngine` | |
| * before awaiting the durable deferred tied to the clock. | |
| * | |
| * @since 4.0.0 | |
| */ | |
| import * as Context from "../../Context.js"; | |
| import * as Duration from "../../Duration.js"; | |
| import * as Effect from "../../Effect.js"; | |
| import * as Activity from "./Activity.js"; | |
| import * as DurableDeferred from "./DurableDeferred.js"; | |
| const TypeId = "~effect/workflow/DurableClock"; | |
| /** | |
| * Creates a durable clock definition and its associated deferred wake-up | |
| * signal. | |
| * | |
| * @category constructors | |
| * @since 4.0.0 | |
| */ | |
| export const make = options => ({ | |
| [TypeId]: TypeId, | |
| name: options.name, | |
| duration: Duration.fromInputUnsafe(options.duration), | |
| deferred: DurableDeferred.make(`DurableClock/${options.name}`) | |
| }); | |
| const EngineTag = /*#__PURE__*/Context.Service("effect/workflow/WorkflowEngine"); | |
| const InstanceTag = /*#__PURE__*/Context.Service("effect/workflow/WorkflowEngine/WorkflowInstance"); | |
| /** | |
| * Waits inside a workflow, using an in-memory activity for durations at or | |
| * below the threshold and scheduling a durable clock for longer durations. | |
| * | |
| * @category sleeping | |
| * @since 4.0.0 | |
| */ | |
| export const sleep = /*#__PURE__*/Effect.fnUntraced(function* (options) { | |
| const duration = Duration.fromInputUnsafe(options.duration); | |
| if (Duration.isZero(duration)) { | |
| return; | |
| } | |
| const inMemoryThreshold = options.inMemoryThreshold ? Duration.fromInputUnsafe(options.inMemoryThreshold) : defaultInMemoryThreshold; | |
| if (Duration.isLessThanOrEqualTo(duration, inMemoryThreshold)) { | |
| return yield* Activity.make({ | |
| name: `DurableClock/${options.name}`, | |
| execute: Effect.sleep(duration) | |
| }); | |
| } | |
| const engine = yield* EngineTag; | |
| const instance = yield* InstanceTag; | |
| const clock = make(options); | |
| yield* engine.scheduleClock(instance.workflow, { | |
| executionId: instance.executionId, | |
| clock | |
| }); | |
| return yield* DurableDeferred.await(clock.deferred); | |
| }); | |
| const defaultInMemoryThreshold = /*#__PURE__*/Duration.seconds(60); | |
| //# sourceMappingURL=DurableClock.js.map |
Xet Storage Details
- Size:
- 2.26 kB
- Xet hash:
- 0be703834232c2c50a97f90bbe4c70ae39cb6b9426556e61efe571b3ba00bb7d
·
Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.