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