Hyperlinkv0.8.0-beta.28

Effect

Effect.runForkWithconsteffect/Effect.ts:8880
<R>(context: Context.Context<R>): <A, E>(
  effect: Effect<A, E, R>,
  options?: RunOptions | undefined
) => Fiber<A, E>

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)
running
Source effect/Effect.ts:88803 lines
export const runForkWith: <R>(
  context: Context.Context<R>
) => <A, E>(effect: Effect<A, E, R>, options?: RunOptions | undefined) => Fiber<A, E> = internal.runForkWith
Referenced by 8 symbols