effect-io-ai

Package: effect
Module: Effect

Effect.runForkWith

Runs an effect in the background with the provided services.

When to use

Use when an effect still requires services, you already have a Context, and you want a background fiber.

Example (Running with services in the background)

import { Context, Effect } from "effect"

interface Logger {
  log: (message: string) => void
}

const Logger = Context.Service<Logger>("Logger")

const services = Context.make(Logger, {
  log: (message) => console.log(message)
})

const program = Effect.gen(function*() {
  const logger = yield* Logger
  logger.log("Hello from service!")
  return "done"
})

const fiber = Effect.runForkWith(services)(program)

Signature

declare const runForkWith: <R>(context: Context.Context<R>) => <A, E>(effect: Effect<A, E, R>, options?: RunOptions | undefined) => Fiber<A, E>

Source

Since v4.0.0