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

Function makeUnsafe

packages/effect/src/unstable/workflow/WorkflowEngine.ts:464–640  ·  view source on GitHub ↗
(options: Encoded)

Source from the content-addressed store, hash-verified

462 * @since 4.0.0
463 */
464export const makeUnsafe = (options: Encoded): WorkflowEngine["Service"] =>
465 WorkflowEngine.of({
466 register: Effect.fnUntraced(function*(workflow, execute) {
467 const services = yield* Effect.context<WorkflowEngine>()
468 yield* options.register(workflow, (payload, executionId) =>
469 Effect.suspend(() =>
470 execute(payload, executionId)
471 ).pipe(
472 Effect.updateContext(
473 (input) => Context.merge(services, input) as Context.Context<any>
474 )
475 ))
476 }),
477 execute: Effect.fnUntraced(function*<
478 Name extends string,
479 Payload extends Workflow.AnyStructSchema,
480 Success extends Schema.Top,
481 Error extends Schema.Top,
482 const Discard extends boolean = false
483 >(
484 self: Workflow.Workflow<Name, Payload, Success, Error>,
485 opts: {
486 readonly executionId: string
487 readonly payload: Payload["Type"]
488 readonly discard?: Discard | undefined
489 readonly suspendedRetrySchedule?:
490 | Schedule.Schedule<any, unknown>
491 | undefined
492 }
493 ) {
494 const payload = opts.payload
495 const executionId = opts.executionId
496 const suspendedRetrySchedule = opts.suspendedRetrySchedule ?? defaultRetrySchedule
497 yield* Effect.annotateCurrentSpan({ executionId })
498 let result = Option.none<Workflow.Result<Success["Type"], Error["Type"]>>()
499
500 // link interruption with parent workflow
501 const parentInstance = yield* Effect.serviceOption(WorkflowInstance)
502 if (Option.isSome(parentInstance)) {
503 const instance = parentInstance.value
504 yield* Effect.addFinalizer(() => {
505 if (!instance.interrupted || (Option.isSome(result) && result.value._tag === "Complete")) {
506 return Effect.void
507 }
508 return options.interrupt(self, executionId)
509 })
510 }
511 const run = options.execute(self, {
512 executionId,
513 payload: payload as object,
514 discard: opts.discard ?? false,
515 parent: Option.getOrUndefined(parentInstance)
516 }) as Effect.Effect<Workflow.Result<Success["Type"], Error["Type"]>>
517
518 if (opts.discard) {
519 yield* run
520 return executionId
521 }

Callers 1

WorkflowEngine.tsFile · 0.70

Calls 10

contextMethod · 0.80
registerMethod · 0.80
mergeMethod · 0.80
addFinalizerMethod · 0.80
someMethod · 0.80
executeFunction · 0.70
ofMethod · 0.65
pipeMethod · 0.65
interruptMethod · 0.45
executeMethod · 0.45

Tested by

no test coverage detected