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

Function async_

packages/effect/src/internal/core.ts:512–554  ·  view source on GitHub ↗
(
  resume: (
    callback: (_: Effect.Effect<A, E, R>) => void,
    signal: AbortSignal
  ) => void | Effect.Effect<void, never, R>,
  blockingOn: FiberId.FiberId = FiberId.none
)

Source from the content-addressed store, hash-verified

510): Effect.Effect<A, E, R> => suspend(() => unsafeAsync(register, blockingOn))
511
512const async_ = <A, E = never, R = never>(
513 resume: (
514 callback: (_: Effect.Effect<A, E, R>) => void,
515 signal: AbortSignal
516 ) => void | Effect.Effect<void, never, R>,
517 blockingOn: FiberId.FiberId = FiberId.none
518): Effect.Effect<A, E, R> => {
519 return custom(resume, function() {
520 let backingResume: ((_: Effect.Effect<A, E, R>) => void) | undefined = undefined
521 let pendingEffect: Effect.Effect<A, E, R> | undefined = undefined
522 function proxyResume(effect: Effect.Effect<A, E, R>) {
523 if (backingResume) {
524 backingResume(effect)
525 } else if (pendingEffect === undefined) {
526 pendingEffect = effect
527 }
528 }
529 const effect = new EffectPrimitive(OpCodes.OP_ASYNC) as any
530 effect.effect_instruction_i0 = (resume: (_: Effect.Effect<A, E, R>) => void) => {
531 backingResume = resume
532 if (pendingEffect) {
533 resume(pendingEffect)
534 }
535 }
536 effect.effect_instruction_i1 = blockingOn
537 let cancelerRef: Effect.Effect<void, never, R> | void = undefined
538 let controllerRef: AbortController | void = undefined
539 if (this.effect_instruction_i0.length !== 1) {
540 controllerRef = new AbortController()
541 cancelerRef = internalCall(() => this.effect_instruction_i0(proxyResume, controllerRef!.signal))
542 } else {
543 cancelerRef = internalCall(() => (this.effect_instruction_i0 as any)(proxyResume))
544 }
545 return (cancelerRef || controllerRef) ?
546 onInterrupt(effect, (_) => {
547 if (controllerRef) {
548 controllerRef.abort()
549 }
550 return cancelerRef ?? void_
551 }) :
552 effect
553 })
554}
555export {
556 /** @internal */
557 async_ as async

Callers

nothing calls this directly

Calls 2

customFunction · 0.70
resumeFunction · 0.70

Tested by

no test coverage detected