| 1649 | } |
| 1650 | |
| 1651 | pollUpTo(n: number): Array<A> { |
| 1652 | if (this.unsubscribed) { |
| 1653 | return [] |
| 1654 | } |
| 1655 | this.subscriberIndex = Math.max(this.subscriberIndex, this.self.subscribersIndex) |
| 1656 | const size = this.self.publisherIndex - this.subscriberIndex |
| 1657 | const toPoll = Math.min(n, size) |
| 1658 | if (toPoll <= 0) { |
| 1659 | return [] |
| 1660 | } |
| 1661 | const builder: Array<A> = [] |
| 1662 | const pollUpToIndex = this.subscriberIndex + toPoll |
| 1663 | while (this.subscriberIndex !== pollUpToIndex) { |
| 1664 | const index = this.subscriberIndex % this.self.capacity |
| 1665 | const a = this.self.array[index] as A |
| 1666 | this.self.subscribers[index] -= 1 |
| 1667 | if (this.self.subscribers[index] === 0) { |
| 1668 | this.self.array[index] = AbsentValue as unknown as A |
| 1669 | this.self.subscribersIndex += 1 |
| 1670 | } |
| 1671 | builder.push(a) |
| 1672 | this.subscriberIndex += 1 |
| 1673 | } |
| 1674 | |
| 1675 | return builder |
| 1676 | } |
| 1677 | |
| 1678 | unsubscribe(): void { |
| 1679 | if (!this.unsubscribed) { |