| 82 | * @since 4.0.0 |
| 83 | */ |
| 84 | export const make = < |
| 85 | Success extends Schema.Constraint = Schema.Void, |
| 86 | Error extends Schema.Constraint = Schema.Never |
| 87 | >( |
| 88 | name: string, |
| 89 | options?: { |
| 90 | readonly success?: Success | undefined |
| 91 | readonly error?: Error | undefined |
| 92 | } |
| 93 | ): DurableDeferred<Success, Error> => { |
| 94 | const successSchema = options?.success ?? (Schema.Void as any as Success) |
| 95 | const errorSchema = options?.error ?? (Schema.Never as any as Error) |
| 96 | return { |
| 97 | [TypeId]: TypeId as typeof TypeId, |
| 98 | name, |
| 99 | successSchema, |
| 100 | errorSchema, |
| 101 | exitSchema: Schema.Exit( |
| 102 | Schema.toCodecJson(successSchema), |
| 103 | Schema.toCodecJson(errorSchema), |
| 104 | Schema.toCodecJson(Schema.Defect()) |
| 105 | ) as any, |
| 106 | withActivityAttempt: Effect.gen(function*() { |
| 107 | const attempt = yield* CurrentAttempt |
| 108 | return make(`${name}/${attempt}`, { |
| 109 | success: successSchema, |
| 110 | error: errorSchema |
| 111 | }) |
| 112 | }) |
| 113 | } |
| 114 | } |
| 115 | |
| 116 | const EngineTag = Context.Service<WorkflowEngine, WorkflowEngine["Service"]>( |
| 117 | "effect/workflow/WorkflowEngine" satisfies typeof WorkflowEngine.key |