MCPcopy Create free account
hub / github.com/Effect-TS/effect / UnboundedPubSubSubscription

Class UnboundedPubSubSubscription

packages/effect/src/PubSub.ts:2356–2464  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2354}
2355
2356class UnboundedPubSubSubscription<in out A> implements PubSub.BackingSubscription<A> {
2357 private self: UnboundedPubSub<A>
2358 private subscriberHead: Node<A>
2359 private subscriberIndex: number
2360 private unsubscribed: boolean
2361
2362 constructor(
2363 self: UnboundedPubSub<A>,
2364 subscriberHead: Node<A>,
2365 subscriberIndex: number,
2366 unsubscribed: boolean
2367 ) {
2368 this.self = self
2369 this.subscriberHead = subscriberHead
2370 this.subscriberIndex = subscriberIndex
2371 this.unsubscribed = unsubscribed
2372 }
2373
2374 isEmpty(): boolean {
2375 if (this.unsubscribed) {
2376 return true
2377 }
2378 let empty = true
2379 let loop = true
2380 while (loop) {
2381 if (this.subscriberHead === this.self.publisherTail) {
2382 loop = false
2383 } else {
2384 if (this.subscriberHead.next!.value !== AbsentValue) {
2385 empty = false
2386 loop = false
2387 } else {
2388 this.subscriberHead = this.subscriberHead.next!
2389 this.subscriberIndex += 1
2390 }
2391 }
2392 }
2393 return empty
2394 }
2395
2396 size() {
2397 if (this.unsubscribed) {
2398 return 0
2399 }
2400 return this.self.publisherIndex - Math.max(this.subscriberIndex, this.self.subscribersIndex)
2401 }
2402
2403 poll(): A | MutableList.Empty {
2404 if (this.unsubscribed) {
2405 return MutableList.Empty
2406 }
2407 let loop = true
2408 let polled: A | MutableList.Empty = MutableList.Empty
2409 while (loop) {
2410 if (this.subscriberHead === this.self.publisherTail) {
2411 loop = false
2412 } else {
2413 const elem = this.subscriberHead.next!.value

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected