Package: effect
Module: Effect
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
Signature
declare const runCallback: <A, E>(effect: Effect<A, E, never>, options?: (RunOptions & { readonly onExit: (exit: Exit.Exit<A, E>) => void; }) | undefined) => (interruptor?: number | undefined) => void
Since v2.0.0