(n: number)
| 244 | return core.succeed([messages, this.releaseCapacity()]) |
| 245 | }) |
| 246 | takeN(n: number): Effect<readonly [messages: Chunk.Chunk<A>, done: boolean], E> { |
| 247 | return core.suspend(() => { |
| 248 | if (this.state._tag === "Done") { |
| 249 | return core.exitAs(this.state.exit, constDone) |
| 250 | } else if (n <= 0) { |
| 251 | return core.succeed([empty, false]) |
| 252 | } else if ( |
| 253 | this.capacity <= 0 && this.messages.length === 0 && this.messagesChunk.length === 0 && |
| 254 | this.state.offers.size > 0 |
| 255 | ) { |
| 256 | this.capacity = 1 |
| 257 | this.releaseCapacity() |
| 258 | this.capacity = 0 |
| 259 | const messages = Chunk.of(this.messages.pop()!) |
| 260 | return core.succeed([messages, this.releaseCapacity()]) |
| 261 | } |
| 262 | n = Math.min(n, this.capacity || 1) |
| 263 | let messages: Chunk.Chunk<A> |
| 264 | if (n <= this.messagesChunk.length) { |
| 265 | messages = Chunk.take(this.messagesChunk, n) |
| 266 | this.messagesChunk = Chunk.drop(this.messagesChunk, n) |
| 267 | } else if (n <= this.messages.length + this.messagesChunk.length) { |
| 268 | this.messagesChunk = Chunk.appendAll(this.messagesChunk, Chunk.unsafeFromArray(this.messages)) |
| 269 | this.messages = [] |
| 270 | messages = Chunk.take(this.messagesChunk, n) |
| 271 | this.messagesChunk = Chunk.drop(this.messagesChunk, n) |
| 272 | } else { |
| 273 | return core.zipRight(this.awaitTake, this.takeN(n)) |
| 274 | } |
| 275 | return core.succeed([messages, this.releaseCapacity()]) |
| 276 | }) |
| 277 | } |
| 278 | unsafeTake(): Exit<A, E | NoSuchElementException> | undefined { |
| 279 | if (this.state._tag === "Done") { |
| 280 | return core.exitZipRight(this.state.exit, core.exitFail(new NoSuchElementException())) |
nothing calls this directly
no test coverage detected