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

Class BoundedPubSubArbSubscription

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

Source from the content-addressed store, hash-verified

1622 )
1623 }
1624
1625 size() {
1626 if (this.unsubscribed) {
1627 return 0
1628 }
1629 return this.self.publisherIndex - Math.max(this.subscriberIndex, this.self.subscribersIndex)
1630 }
1631
1632 poll(): A | MutableList.Empty {
1633 if (this.unsubscribed) {
1634 return MutableList.Empty
1635 }
1636 this.subscriberIndex = Math.max(this.subscriberIndex, this.self.subscribersIndex)
1637 if (this.subscriberIndex !== this.self.publisherIndex) {
1638 const index = this.subscriberIndex % this.self.capacity
1639 const elem = this.self.array[index]!
1640 this.self.subscribers[index] -= 1
1641 if (this.self.subscribers[index] === 0) {
1642 this.self.array[index] = AbsentValue as unknown as A
1643 this.self.subscribersIndex += 1
1644 }
1645 this.subscriberIndex += 1
1646 return elem
1647 }
1648 return MutableList.Empty
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) {
1680 this.unsubscribed = true
1681 this.self.subscriberCount -= 1

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…