MCPcopy Create free account
hub / github.com/Effect-TS/effect / pollUpTo

Method pollUpTo

packages/effect/src/PubSub.ts:1847–1871  ·  view source on GitHub ↗
(n: number)

Source from the content-addressed store, hash-verified

1845 }
1846
1847 pollUpTo(n: number): Array<A> {
1848 if (this.unsubscribed) {
1849 return []
1850 }
1851 this.subscriberIndex = Math.max(this.subscriberIndex, this.self.subscribersIndex)
1852 const size = this.self.publisherIndex - this.subscriberIndex
1853 const toPoll = Math.min(n, size)
1854 if (toPoll <= 0) {
1855 return []
1856 }
1857 const builder: Array<A> = []
1858 const pollUpToIndex = this.subscriberIndex + toPoll
1859 while (this.subscriberIndex !== pollUpToIndex) {
1860 const index = this.subscriberIndex & this.self.mask
1861 const elem = this.self.array[index] as A
1862 this.self.subscribers[index] -= 1
1863 if (this.self.subscribers[index] === 0) {
1864 this.self.array[index] = AbsentValue as unknown as A
1865 this.self.subscribersIndex += 1
1866 }
1867 builder.push(elem)
1868 this.subscriberIndex += 1
1869 }
1870 return builder
1871 }
1872
1873 unsubscribe(): void {
1874 if (!this.unsubscribed) {

Callers

nothing calls this directly

Calls 1

pushMethod · 0.80

Tested by

no test coverage detected