MCPcopy
hub / github.com/Effect-TS/effect / shard

Function shard

packages/effect/test/Fiber.test.ts:128–143  ·  view source on GitHub ↗
(
        queue: Queue.Queue<A>,
        n: number,
        worker: (a: A) => Effect.Effect<void, E, R>
      )

Source from the content-addressed store, hash-verified

126 it.effect("shard example", () =>
127 Effect.gen(function*() {
128 const shard = <A, E, R>(
129 queue: Queue.Queue<A>,
130 n: number,
131 worker: (a: A) => Effect.Effect<void, E, R>
132 ): Effect.Effect<never, E, R> => {
133 const worker1 = pipe(
134 Queue.take(queue),
135 Effect.flatMap((a) => Effect.uninterruptible(worker(a))),
136 Effect.forever
137 )
138 return pipe(
139 Effect.forkAll(Array.makeBy(n, () => worker1)),
140 Effect.flatMap(Fiber.join),
141 Effect.zipRight(Effect.never)
142 )
143 }
144 const worker = (n: number) => {
145 if (n === 100) {
146 return pipe(Queue.shutdown(queue), Effect.zipRight(Effect.fail("fail")))

Callers 1

Fiber.test.tsFile · 0.85

Calls 3

pipeFunction · 0.90
workerFunction · 0.70
takeMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…