Efficiently Awaiting All Fibers in a FiberSet Without Hanging

import { Effect, FiberSet } from "effect";

const task = (ms: number) =>
  Effect.gen(function* () {
    console.log("task start", ms);
    yield* Effect.sleep(ms);
    console.log("task end", ms);
  });

const main = Effect.gen(function* () {
  const fs = yield* FiberSet.make();
  yield* FiberSet.run(fs, task(50));
  yield* FiberSet.run(fs, task(100));
  yield* FiberSet.run(fs, task(200));

  yield* Effect.sleep("500 millis");
  const size = yield* FiberSet.size(fs);
  console.log("size", size);

  yield* FiberSet.join(fs);
}).pipe(Effect.scoped);

await Effect.runPromise(main);
/*
task start 50
task start 100
task start 200
task end 50
task end 100
task end 200
size 0
<hangs>
*/


is there a way to await all of the fibers in a fiber set and have it not hang?
like I could make a set, add all my fibers to it, and then Fiber.joinAll but I feel like there has to be a better way
Was this page helpful?