()
| 364 | }) |
| 365 | } |
| 366 | private releaseCapacity(): boolean { |
| 367 | if (this.state._tag === "Done") { |
| 368 | return this.state.exit._tag === "Success" |
| 369 | } else if (this.state.offers.size === 0) { |
| 370 | if (this.state._tag === "Closing" && this.messages.length === 0 && this.messagesChunk.length === 0) { |
| 371 | this.finalize(this.state.exit) |
| 372 | return this.state.exit._tag === "Success" |
| 373 | } |
| 374 | return false |
| 375 | } |
| 376 | let n = this.capacity - this.messages.length - this.messagesChunk.length |
| 377 | for (const entry of this.state.offers) { |
| 378 | if (n === 0) return false |
| 379 | else if (entry._tag === "Single") { |
| 380 | this.messages.push(entry.message) |
| 381 | n-- |
| 382 | entry.resume(exitTrue) |
| 383 | this.state.offers.delete(entry) |
| 384 | } else { |
| 385 | for (; entry.offset < entry.remaining.length; entry.offset++) { |
| 386 | if (n === 0) return false |
| 387 | this.messages.push(entry.remaining[entry.offset]) |
| 388 | n-- |
| 389 | } |
| 390 | entry.resume(exitEmpty) |
| 391 | this.state.offers.delete(entry) |
| 392 | } |
| 393 | } |
| 394 | return false |
| 395 | } |
| 396 | private awaitTake = core.asyncInterrupt<void, E>((resume) => { |
| 397 | if (this.state._tag === "Done") { |
| 398 | return resume(this.state.exit) |
no test coverage detected