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

Class UnboundedPubSub

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

Source from the content-addressed store, hash-verified

2063 this.replayBuffer = replayBuffer
2064 }
2065
2066 replayWindow(): PubSub.ReplayWindow<A> {
2067 return this.replayBuffer ? new ReplayWindowImpl(this.replayBuffer) : emptyReplayWindow
2068 }
2069
2070 isEmpty(): boolean {
2071 return this.publisherHead === this.publisherTail
2072 }
2073
2074 isFull(): boolean {
2075 return false
2076 }
2077
2078 size(): number {
2079 return this.publisherIndex - this.subscribersIndex
2080 }
2081
2082 publish(value: A): boolean {
2083 const replayIndex = this.replayBuffer?.offer(value)
2084 const subscribers = this.publisherTail.subscribers
2085 if (subscribers !== 0) {
2086 const node: Node<A> = {
2087 value,
2088 replayIndex,
2089 subscribers,
2090 next: null
2091 }
2092 this.publisherTail.next = node
2093 this.publisherTail = this.publisherTail.next
2094 this.publisherIndex += 1
2095 }
2096 return true
2097 }
2098
2099 publishAll(elements: Iterable<A>): Array<A> {
2100 if (this.publisherTail.subscribers !== 0) {
2101 for (const a of elements) {
2102 this.publish(a)
2103 }
2104 } else if (this.replayBuffer) {
2105 this.replayBuffer.offerAll(elements)
2106 }
2107 return []
2108 }
2109
2110 slide(): void {
2111 if (this.publisherHead !== this.publisherTail) {
2112 const node = this.publisherHead.next!
2113 const value = node.value as A
2114 this.publisherHead = this.publisherHead.next!
2115 this.publisherHead.value = AbsentValue
2116 this.subscribersIndex += 1
2117 this.replayBuffer?.slide(value, node.replayIndex!)
2118 }
2119 }
2120
2121 subscribe(): PubSub.BackingSubscription<A> {
2122 this.publisherTail.subscribers += 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…