| 1889 | } |
| 1890 | |
| 1891 | class BoundedPubSubSingle<in out A> implements PubSub.Atomic<A> { |
| 1892 | publisherIndex = 0 |
| 1893 | subscriberCount = 0 |
| 1894 | subscribers = 0 |
| 1895 | value: A = AbsentValue as unknown as A |
| 1896 | replayIndex = 0 |
| 1897 | |
| 1898 | readonly capacity = 1 |
| 1899 | readonly replayBuffer: ReplayBuffer<A> | undefined |
| 1900 | |
| 1901 | constructor(replayBuffer: ReplayBuffer<A> | undefined) { |
| 1902 | this.replayBuffer = replayBuffer |
| 1903 | } |
| 1904 | |
| 1905 | replayWindow(): PubSub.ReplayWindow<A> { |
| 1906 | return this.replayBuffer ? new ReplayWindowImpl(this.replayBuffer) : emptyReplayWindow |
| 1907 | } |
| 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) |
nothing calls this directly
no outgoing calls
no test coverage detected