| 1990 | return ( |
| 1991 | this.unsubscribed || |
| 1992 | this.self.subscribers === 0 || |
| 1993 | this.subscriberIndex === this.self.publisherIndex |
| 1994 | ) |
| 1995 | } |
| 1996 | |
| 1997 | size() { |
| 1998 | return this.isEmpty() ? 0 : 1 |
| 1999 | } |
| 2000 | |
| 2001 | poll(): A | MutableList.Empty { |
| 2002 | if (this.isEmpty()) { |
| 2003 | return MutableList.Empty |
| 2004 | } |
| 2005 | const elem = this.self.value |
| 2006 | this.self.subscribers -= 1 |
| 2007 | if (this.self.subscribers === 0) { |
| 2008 | this.self.value = AbsentValue as unknown as A |
| 2009 | } |
| 2010 | this.subscriberIndex += 1 |
| 2011 | return elem |
| 2012 | } |
| 2013 | |
| 2014 | pollUpTo(n: number): Array<A> { |
| 2015 | if (this.isEmpty() || n < 1) { |
| 2016 | return [] |
| 2017 | } |
| 2018 | const a = this.self.value |
| 2019 | this.self.subscribers -= 1 |
| 2020 | if (this.self.subscribers === 0) { |
| 2021 | this.self.value = AbsentValue as unknown as A |
| 2022 | } |
| 2023 | this.subscriberIndex += 1 |
| 2024 | return [a] |
| 2025 | } |
| 2026 | |
| 2027 | unsubscribe(): void { |
| 2028 | if (!this.unsubscribed) { |
| 2029 | this.unsubscribed = true |
| 2030 | this.self.subscriberCount -= 1 |
| 2031 | if (this.subscriberIndex !== this.self.publisherIndex) { |
| 2032 | this.self.subscribers -= 1 |
| 2033 | if (this.self.subscribers === 0) { |
| 2034 | this.self.value = AbsentValue as unknown as A |
| 2035 | } |
| 2036 | } |
| 2037 | } |
| 2038 | } |
| 2039 | } |
| 2040 | |
| 2041 | interface Node<out A> { |
| 2042 | value: A | AbsentValue |
| 2043 | replayIndex: number | undefined |
| 2044 | subscribers: number |
| 2045 | next: Node<A> | null |
| 2046 | } |
| 2047 | |
| 2048 | class UnboundedPubSub<in out A> implements PubSub.Atomic<A> { |
| 2049 | publisherHead: Node<A> = { |
nothing calls this directly
no outgoing calls
no test coverage detected
searching dependent graphs…