| 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) |