MCPcopy Create free account
hub / github.com/effect-app/libs / BoundedPubSubPow2

Class BoundedPubSubPow2

repos/effect/packages/effect/src/PubSub.ts:1718–1815  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1716
1717 replayWindow(): PubSub.ReplayWindow<A> {
1718 return this.replayBuffer ? new ReplayWindowImpl(this.replayBuffer) : emptyReplayWindow
1719 }
1720
1721 isEmpty(): boolean {
1722 return this.publisherIndex === this.subscribersIndex
1723 }
1724
1725 isFull(): boolean {
1726 return this.publisherIndex === this.subscribersIndex + this.capacity
1727 }
1728
1729 size(): number {
1730 return this.publisherIndex - this.subscribersIndex
1731 }
1732
1733 publish(value: A): boolean {
1734 if (this.isFull()) {
1735 return false
1736 }
1737 const replayIndex = this.replayBuffer?.offer(value)
1738 if (this.subscriberCount !== 0) {
1739 const index = this.publisherIndex & this.mask
1740 this.array[index] = value
1741 if (replayIndex !== undefined) {
1742 this.replayIndices[index] = replayIndex
1743 }
1744 this.subscribers[index] = this.subscriberCount
1745 this.publisherIndex += 1
1746 }
1747 return true
1748 }
1749
1750 publishAll(elements: Iterable<A>): Array<A> {
1751 if (this.subscriberCount === 0) {
1752 if (this.replayBuffer) {
1753 this.replayBuffer.offerAll(elements)
1754 }
1755 return []
1756 }
1757 const chunk = Arr.fromIterable(elements)
1758 const n = chunk.length
1759 const size = this.publisherIndex - this.subscribersIndex
1760 const available = this.capacity - size
1761 const forPubSub = Math.min(n, available)
1762 if (forPubSub === 0) {
1763 return chunk
1764 }
1765 let iteratorIndex = 0
1766 const publishAllIndex = this.publisherIndex + forPubSub
1767 while (this.publisherIndex !== publishAllIndex) {
1768 const elem = chunk[iteratorIndex++]
1769 const index = this.publisherIndex & this.mask
1770 this.array[index] = elem
1771 const replayIndex = this.replayBuffer?.offer(elem)
1772 if (replayIndex !== undefined) {
1773 this.replayIndices[index] = replayIndex
1774 }
1775 this.subscribers[index] = this.subscriberCount

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…