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

Function takeRemainderLoop

repos/effect/packages/effect/src/PubSub.ts:1349–1380  ·  view source on GitHub ↗
(
  self: Subscription<A>,
  min: number,
  max: number,
  acc: Array<A>
)

Source from the content-addressed store, hash-verified

1347 }
1348 if (remaining > 1) {
1349 return Effect.flatMap(take(self), (b) => {
1350 acc.push(b)
1351 return takeRemainderLoop(
1352 self,
1353 remaining - 1,
1354 max - bs.length - 1,
1355 acc
1356 )
1357 })
1358 }
1359 return Effect.succeed(acc)
1360 })
1361}
1362
1363/**
1364 * Returns the number of messages currently available in the subscription as an
1365 * `Effect`.
1366 *
1367 * **When to use**
1368 *
1369 * Use when checking a subscription from effectful code and shutdown should
1370 * interrupt the effect.
1371 *
1372 * **Details**
1373 *
1374 * The count includes replay-buffered messages. If the subscription has been
1375 * shut down, the effect interrupts.
1376 *
1377 * **Example** (Checking remaining messages)
1378 *
1379 * ```ts import.meta.vitest
1380 * import { Effect, PubSub } from "effect"
1381 *
1382 * const program = Effect.scoped(Effect.gen(function*() {
1383 * const pubsub = yield* PubSub.bounded<string>(10)

Callers 1

PubSub.tsFile · 0.85

Calls 4

pushMethod · 0.80
takeFunction · 0.70
mapMethod · 0.65
succeedMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…