Hyperlinkv0.8.0-beta.28

Console

Console.withTimeconsteffect/Console.ts:638
(label?: string): <A, E, R>(
  self: Effect.Effect<A, E, R>
) => Effect.Effect<A, E, R>
<A, E, R>(self: Effect.Effect<A, E, R>, label?: string): Effect.Effect<
  A,
  E,
  R
>

Runs an Effect with a console timer, starting the timer before execution and ending it after the Effect completes.

Example (Timing an effect)

import { Console, Effect } from "effect"

const program = Effect.gen(function*() {
  yield* Console.withTime(
    Effect.gen(function*() {
      yield* Effect.sleep("1 second")
      yield* Console.log("Operation completed")
    }),
    "my-operation"
  )
})
accessors
Source effect/Console.ts:63816 lines
export const withTime = dual<
  (label?: string) => <A, E, R>(self: Effect.Effect<A, E, R>) => Effect.Effect<A, E, R>,
  <A, E, R>(self: Effect.Effect<A, E, R>, label?: string) => Effect.Effect<A, E, R>
>((args) => core.isEffect(args[0]), (self, label) =>
  consoleWith((console) =>
    effect.acquireUseRelease(
      effect.sync(() => {
        console.time(label)
      }),
      () => self,
      () =>
        effect.sync(() => {
          console.timeEnd(label)
        })
    )
  ))