| 2119 | } |
| 2120 | |
| 2121 | class BoundedPubSubSingle<in out A> implements PubSub.Atomic<A> { |
| 2122 | publisherIndex = 0 |
| 2123 | subscriberCount = 0 |
| 2124 | subscribers = 0 |
| 2125 | value: A = AbsentValue as unknown as A |
| 2126 | replayIndex = 0 |
| 2127 | |
| 2128 | readonly capacity = 1 |
| 2129 | readonly replayBuffer: ReplayBuffer<A> | undefined |
| 2130 | |
| 2131 | constructor(replayBuffer: ReplayBuffer<A> | undefined) { |
| 2132 | this.replayBuffer = replayBuffer |
| 2133 | } |
| 2134 | |
| 2135 | replayWindow(): PubSub.ReplayWindow<A> { |
| 2136 | return this.replayBuffer ? new ReplayWindowImpl(this.replayBuffer) : emptyReplayWindow |
| 2137 | } |
| 2138 | |
| 2139 | pipe() { |
| 2140 | return pipeArguments(this, arguments) |
| 2141 | } |
| 2142 | |
| 2143 | isEmpty(): boolean { |
| 2144 | return this.subscribers === 0 |
| 2145 | } |
| 2146 | |
| 2147 | isFull(): boolean { |
| 2148 | return !this.isEmpty() |
| 2149 | } |
| 2150 | |
| 2151 | size(): number { |
| 2152 | return this.isEmpty() ? 0 : 1 |
| 2153 | } |
| 2154 | |
| 2155 | publish(value: A): boolean { |
| 2156 | if (this.isFull()) { |
| 2157 | return false |
| 2158 | } |
| 2159 | const replayIndex = this.replayBuffer?.offer(value) |
| 2160 | if (this.subscriberCount !== 0) { |
| 2161 | this.value = value |
| 2162 | if (replayIndex !== undefined) { |
| 2163 | this.replayIndex = replayIndex |
| 2164 | } |
| 2165 | this.subscribers = this.subscriberCount |
| 2166 | this.publisherIndex += 1 |
| 2167 | } |
| 2168 | return true |
| 2169 | } |
| 2170 | |
| 2171 | publishAll(elements: Iterable<A>): Array<A> { |
| 2172 | if (this.subscriberCount === 0) { |
| 2173 | if (this.replayBuffer) { |
| 2174 | this.replayBuffer.offerAll(elements) |
| 2175 | } |
| 2176 | return [] |
| 2177 | } |
| 2178 | const chunk = Arr.fromIterable(elements) |
nothing calls this directly
no outgoing calls
no test coverage detected