MCPcopy Index your code
hub / github.com/Effect-TS/effect / boot

Function boot

packages/experimental/src/Machine.ts:470–835  ·  view source on GitHub ↗
(
  self: M,
  ...[input, options]: [Machine.Input<M>] extends [void] ? [
      input?: Machine.Input<M>,
      options?: { readonly previousState?: Machine.State<M> }
    ] :
    [
      input: Machine.Input<M>,
      options?: { readonly previousState?: Machine.State<M> }
    ]
)

Source from the content-addressed store, hash-verified

468 * @category runtime
469 */
470export const boot = <
471 M extends Machine.Any
472>(
473 self: M,
474 ...[input, options]: [Machine.Input<M>] extends [void] ? [
475 input?: Machine.Input<M>,
476 options?: { readonly previousState?: Machine.State<M> }
477 ] :
478 [
479 input: Machine.Input<M>,
480 options?: { readonly previousState?: Machine.State<M> }
481 ]
482): Effect.Effect<
483 M extends { readonly [SerializableTypeId]: SerializableTypeId } ? SerializableActor<M> : Actor<M>,
484 never,
485 Machine.Context<M> | Scope.Scope
486> =>
487 Effect.gen(function*() {
488 const context = yield* Effect.context<Machine.Context<M>>()
489 const requests = yield* Queue.unbounded<
490 readonly [
491 Procedure.TaggedRequest.Any,
492 Deferred.Deferred<any, any>,
493 Tracer.AnySpan | undefined,
494 addSpans: boolean
495 ]
496 >()
497 const pubsub = yield* Effect.acquireRelease(
498 PubSub.unbounded<Machine.State<M>>(),
499 PubSub.shutdown
500 )
501 const latch = yield* Deferred.make<void>()
502
503 let currentState: Machine.State<M> = undefined as any
504 let runState: {
505 readonly identifier: string
506 readonly publicTags: Set<string>
507 readonly decodeRequest: (u: unknown) => Effect.Effect<Machine.Public<M>, ParseResult.ParseError>
508 } = {
509 identifier: "Unknown",
510 publicTags: new Set<string>(),
511 decodeRequest: undefined as any
512 }
513
514 const requestContext = <R extends Machine.Public<M>>(request: R) =>
515 Effect.sync(() => {
516 const fiber = Option.getOrThrow(Fiber.getCurrentFiber())
517 const fiberRefs = fiber.getFiberRefs()
518 const context = FiberRefs.getOrDefault(fiberRefs, FiberRef.currentContext)
519
520 const deferred = Deferred.unsafeMake<Request.Success<R>, Request.Error<R>>(fiber.id())
521 const span: Tracer.AnySpan | undefined = context.unsafeMap.get(Tracer.ParentSpan.key)
522 const addSpans = FiberRefs.getOrDefault(fiberRefs, currentTracingEnabled)
523
524 return [request, deferred, span, addSpans] as const
525 })
526
527 const send = <R extends Machine.Public<M>>(request: R) =>

Callers

nothing calls this directly

Calls 15

publishStateFunction · 0.85
identityFunction · 0.85
wrapMethod · 0.80
createMethod · 0.80
failCauseMethod · 0.80
syncMethod · 0.80
forkFunction · 0.70
pipeFunction · 0.70
contextMethod · 0.65
makeMethod · 0.65
pipeMethod · 0.65
mapMethod · 0.65

Tested by

no test coverage detected