Packages

effect

4.1.4 · 11 Nov 2026MIT66.6M / weekRepositoryHomepagenpmAtom feed

Your version

3.5.0

10 Jul 2024Where it was published

3.22.5 is the newest release of 3.x.

In short

1 deprecated13 new5 fixed1 internal

  • Deprecated

    Stream: Use new built-in Types.TupleOf instead of Stream.DynamicTuple and deprecate it

Security

2 advisories affect 3.5.0; 3.22.1 fixes them

Release note

Minor Changes

  • Add renderErrorCause option to Cause.pretty

  • Add RcRef module

    An RcRef wraps a reference counted resource that can be acquired and released multiple times.

    The resource is lazily acquired on the first call to get and released when the last reference is released.

    import { Effect, RcRef } from "effect";
    
    Effect.gen(function* () {
      const ref = yield* RcRef.make({
        acquire: Effect.acquireRelease(Effect.succeed("foo"), () =>
          Effect.log("release foo"),
        ),
      });
    
      // will only acquire the resource once, and release it
      // when the scope is closed
      yield* RcRef.get(ref).pipe(Effect.andThen(RcRef.get(ref)), Effect.scoped);
    });
  • Allowing customizing Stream pubsub strategy

    import { Schedule, Stream } from "effect";
    
    // toPubSub
    Stream.fromSchedule(Schedule.spaced(1000)).pipe(
      Stream.toPubSub({
        capacity: 16, // or "unbounded"
        strategy: "dropping", // or "sliding" / "suspend"
      }),
    );
    
    // also for the broadcast apis
    Stream.fromSchedule(Schedule.spaced(1000)).pipe(
      Stream.broadcastDynamic({
        capacity: 16,
        strategy: "dropping",
      }),
    );
  • Add Duration.isZero, for checking if a Duration is zero

  • Add Success type util for Config.

  • Add Logger.prettyLogger and Logger.pretty

    Logger.pretty is a new logger that leverages the features of the console APIs to provide a more visually appealing output.

    To try it out, provide it to your program:

    import { Effect, Logger } from "effect";
    
    Effect.log("Hello, World!").pipe(Effect.provide(Logger.pretty));
  • Add .groupCollapsed to UnsafeConsole

  • Export Random.make taking hashable values as seed

  • Add replay option to PubSub constructors

    This option adds a replay buffer in front of the given PubSub. The buffer will
    replay the last n messages to any new subscriber.

    Effect.gen(function*() {
      const messages = [1, 2, 3, 4, 5]
      const pubsub = yield* PubSub.bounded<number>({ capacity: 16, replay: 3 })
      yield* PubSub.publishAll(pubsub, messages)
      const sub = yield* PubSub.subscribe(pubsub)
      assert.deepStrictEqual(Chunk.toReadonlyArray(yield* Queue.takeAll(sub)), [3, 4, 5])
    }))
  • Add RcMap module

    An RcMap can contain multiple reference counted resources that can be indexed
    by a key. The resources are lazily acquired on the first call to get and
    released when the last reference is released.

    Complex keys can extend Equal and Hash to allow lookups by value.

    import { Effect, RcMap } from "effect";
    
    Effect.gen(function* () {
      const map = yield* RcMap.make({
        lookup: (key: string) =>
          Effect.acquireRelease(Effect.succeed(`acquired ${key}`), () =>
            Effect.log(`releasing ${key}`),
          ),
      });
    
      // Get "foo" from the map twice, which will only acquire it once
      // It will then be released once the scope closes.
      yield* RcMap.get(map, "foo").pipe(
        Effect.andThen(RcMap.get(map, "foo")),
        Effect.scoped,
      );
    });
  • Ensure Scope is excluded from R in the Channel / Stream run* functions.

    This fix ensures that Scope is now properly excluded from the resulting effect environment.
    The affected functions include run, runCollect, runCount, runDrain and other non-scoped run* in both Stream and Channel modules.
    This fix brings the type declaration in line with the runtime implementation.

  • Stream: Implement "raceAll" operator, which returns a stream that mirrors the first source stream to emit an item.

    import { Stream, Schedule, Console, Effect } from "effect";
    
    const stream = Stream.raceAll(
      Stream.fromSchedule(Schedule.spaced("1 millis")),
      Stream.fromSchedule(Schedule.spaced("2 millis")),
      Stream.fromSchedule(Schedule.spaced("4 millis")),
    ).pipe(Stream.take(6), Stream.tap(Console.log));
    
    Effect.runPromise(Stream.runDrain(stream));
    // Output only from the first stream, the rest streams are interrupted
    // 0
    // 1
    // 2
    // 3
    // 4
    // 5
  • Deprecated

    Stream: Use new built-in Types.TupleOf instead of Stream.DynamicTuple and deprecate it

  • Support ErrorOptions in YieldableError constructor

  • Allow customizing the output buffer for the Stream.async* apis

    import { Stream } from "effect";
    
    Stream.async<string>(
      (emit) => {
        // ...
      },
      {
        bufferSize: 16,
        strategy: "dropping", // you can also use "sliding" or "suspend"
      },
    );

Patch Changes

  • Include Error.cause stack in log output

  • Set stackTraceLimit to 1 in PrettyError to address performance issues

  • Ensure "cause" is rendered in Data.Error output

  • Fix types of UnsafeConsole.group

A whole project to check? Paste its package.json in the dependency check: every deprecated, outdated or vulnerable dependency, with what to upgrade to. Free, no account.