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

Class BoundedPubSubSingle

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

Source from the content-addressed store, hash-verified

1908
1909 pipe() {
1910 return pipeArguments(this, arguments)
1911 }
1912
1913 isEmpty(): boolean {
1914 return this.subscribers === 0
1915 }
1916
1917 isFull(): boolean {
1918 return !this.isEmpty()
1919 }
1920
1921 size(): number {
1922 return this.isEmpty() ? 0 : 1
1923 }
1924
1925 publish(value: A): boolean {
1926 if (this.isFull()) {
1927 return false
1928 }
1929 const replayIndex = this.replayBuffer?.offer(value)
1930 if (this.subscriberCount !== 0) {
1931 this.value = value
1932 if (replayIndex !== undefined) {
1933 this.replayIndex = replayIndex
1934 }
1935 this.subscribers = this.subscriberCount
1936 this.publisherIndex += 1
1937 }
1938 return true
1939 }
1940
1941 publishAll(elements: Iterable<A>): Array<A> {
1942 if (this.subscriberCount === 0) {
1943 if (this.replayBuffer) {
1944 this.replayBuffer.offerAll(elements)
1945 }
1946 return []
1947 }
1948 const chunk = Arr.fromIterable(elements)
1949 if (chunk.length === 0) {
1950 return chunk
1951 }
1952 if (this.publish(chunk[0])) {
1953 return chunk.slice(1)
1954 } else {
1955 return chunk
1956 }
1957 }
1958
1959 slide(): void {
1960 if (this.isFull()) {
1961 const value = this.value
1962 this.subscribers = 0
1963 this.value = AbsentValue as unknown as A
1964 this.replayBuffer?.slide(value, this.replayIndex)
1965 }
1966 }
1967

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…