MCPcopy Create free account
hub / github.com/effect-app/libs / naiveRateLimit

Function naiveRateLimit

packages/infra/src/rateLimit.ts:106–126  ·  view source on GitHub ↗
(
  n: number,
  d: Duration.Duration
)

Source from the content-addressed store, hash-verified

104// }
105
106export function naiveRateLimit(
107 n: number,
108 d: Duration.Duration
109) {
110 return <T>(items: Iterable<T>) => (<R, E, A, R2, E2, A2>(
111 forEachItem: (i: T) => Effect.Effect<A, E, R>,
112 forEachBatch: (a: A[]) => Effect.Effect<A2, E2, R2>
113 ) =>
114 Effect.forEach(
115 Array.chunksOf(items, n),
116 (batch, i) =>
117 ((i === 0)
118 ? Effect.void
119 : Effect.sleep(d))
120 .pipe(Effect.andThen(
121 Effect
122 .forEach(batch, forEachItem, { concurrency: n })
123 .pipe(Effect.flatMap(forEachBatch))
124 ))
125 ))
126}

Callers

nothing calls this directly

Calls 3

forEachMethod · 0.65
pipeMethod · 0.65
sleepMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…