Hyperlinkv0.8.0-beta.28

Effect

Effect.runCallbackconsteffect/Effect.ts:8979
<A, E>(
  effect: Effect<A, E, never>,
  options?:
    | (RunOptions & { readonly onExit: (exit: Exit.Exit<A, E>) => void })
    | undefined
): (interruptor?: number | undefined) => void

Runs an effect asynchronously, registering onExit as a fiber observer and returning an interruptor.

Details

The interruptor calls fiber.interruptUnsafe with the optional interruptor id.

Example (Running with a callback)

import { Console, Effect, Exit } from "effect"

const program = Effect.gen(function*() {
  yield* Console.log("working")
  return "done"
})

const interrupt = Effect.runCallback(program, {
  onExit: (exit) => {
    Effect.runSync(
      Exit.match(exit, {
        onFailure: () => Console.log("failed"),
        onSuccess: (value) => Console.log(`success: ${value}`)
      })
    )
  }
})

// Output:
// working
// success: done

// interrupt() to cancel the fiber if needed
running
Source effect/Effect.ts:89794 lines
export const runCallback: <A, E>(
  effect: Effect<A, E, never>,
  options?: (RunOptions & { readonly onExit: (exit: Exit.Exit<A, E>) => void }) | undefined
) => (interruptor?: number | undefined) => void = internal.runCallback
Referenced by 1 symbols