| 1328 | ) |
| 1329 | |
| 1330 | const takeRemainderLoop = <A>( |
| 1331 | self: Subscription<A>, |
| 1332 | min: number, |
| 1333 | max: number, |
| 1334 | acc: Array<A> |
| 1335 | ): Effect.Effect<Array<A>> => { |
| 1336 | if (max < min) { |
| 1337 | return Effect.succeed(acc) |
| 1338 | } |
| 1339 | return Effect.flatMap(takeUpTo(self, max), (bs) => { |
| 1340 | acc.push(...bs) |
| 1341 | const remaining = min - bs.length |
| 1342 | if (remaining === 1) { |
| 1343 | return Effect.map(take(self), (b) => { |
| 1344 | acc.push(b) |
| 1345 | return acc |
| 1346 | }) |
| 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 |