Parallel Effect Handlers

Async handler + par combinators

Why it matters

  • `par.all()` fans out async computation with typed handlers.
  • Deterministic reduction highlights the champion task without Promises.
par.all()par.race()AsyncConsole Console.capture()Exception.tryCatch()Async.default()
Program
// Multi-capability type: parallel effect composition
// Combines async operations, logging, and error handling
type ParallelProgramCaps = Readonly<{
  console: typeof Console.spec;
  async: typeof Async.spec;
  exception: typeof Exception.spec;
}>;

const program = (): Eff<ParallelSnapshot, ParallelProgramCaps> =>
  seq()
    .let(() =>
      par.all({
        console: () => runTask(consoleTask),
        state: () => runTask(stateTask),
        async: () => runTask(asyncTask),
      })
    )
    .then((results) =>
      pipe(descriptors, (descriptors) =>
        descriptors.map((descriptor) => results[descriptor.id]))
    )
    .then((tasks) => ({
      tasks,
      fastest: pipe(tasks, (ts) =>
        ts.reduce((best, current) =>
          match(toBoolTag(current.delay < best.delay), {
            True: () => current,
            False: () => best,
          }), tasks[0])
      ),
    }))
    .value();

Awaiting execution

Console output, timeline events will render here after you run the program.

Handlers: Console.capture() · Exception.tryCatch() · Async.default()