| 2818 | * @since 4.0.0 |
| 2819 | */ |
| 2820 | export class SlidingStrategy<in out A> implements PubSub.Strategy<A> { |
| 2821 | get shutdown(): Effect.Effect<void> { |
| 2822 | return Effect.void |
| 2823 | } |
| 2824 | |
| 2825 | handleSurplus( |
| 2826 | pubsub: PubSub.Atomic<A>, |
| 2827 | subscribers: PubSub.Subscribers<A>, |
| 2828 | elements: Iterable<A>, |
| 2829 | _isShutdown: MutableRef.MutableRef<boolean>, |
| 2830 | ended: MutableRef.MutableRef<Option.Option<A>> |
| 2831 | ): Effect.Effect<boolean> { |
| 2832 | return Effect.sync(() => { |
| 2833 | if (Option.isSome(ended.current)) return false |
| 2834 | this.slidingPublishUnsafe(pubsub, elements) |
| 2835 | this.completeSubscribersUnsafe(pubsub, subscribers) |
| 2836 | return true |
| 2837 | }) |
| 2838 | } |
| 2839 | |
| 2840 | onPubSubEmptySpaceUnsafe( |
| 2841 | _pubsub: PubSub.Atomic<A>, |
| 2842 | _subscribers: PubSub.Subscribers<A> |
| 2843 | ): void { |
| 2844 | // |
| 2845 | } |
| 2846 | |
| 2847 | completePollersUnsafe( |
| 2848 | pubsub: PubSub.Atomic<A>, |
| 2849 | subscribers: PubSub.Subscribers<A>, |
| 2850 | subscription: PubSub.BackingSubscription<A>, |
| 2851 | pollers: MutableList.MutableList<Deferred.Deferred<A>> |
| 2852 | ): void { |
| 2853 | return strategyCompletePollersUnsafe(this, pubsub, subscribers, subscription, pollers) |
| 2854 | } |
| 2855 | |
| 2856 | completeSubscribersUnsafe(pubsub: PubSub.Atomic<A>, subscribers: PubSub.Subscribers<A>): void { |
| 2857 | return strategyCompleteSubscribersUnsafe(this, pubsub, subscribers) |
| 2858 | } |
| 2859 | |
| 2860 | slidingPublishUnsafe(pubsub: PubSub.Atomic<A>, elements: Iterable<A>): void { |
| 2861 | const it = elements[Symbol.iterator]() |
| 2862 | let next = it.next() |
| 2863 | if (!next.done && pubsub.capacity > 0) { |
| 2864 | let a = next.value |
| 2865 | let loop = true |
| 2866 | while (loop) { |
| 2867 | pubsub.slide() |
| 2868 | const pub = pubsub.publish(a) |
| 2869 | if (pub && (next = it.next()) && !next.done) { |
| 2870 | a = next.value |
| 2871 | } else if (pub) { |
| 2872 | loop = false |
| 2873 | } |
| 2874 | } |
| 2875 | } |
| 2876 | } |
| 2877 | } |
nothing calls this directly
no outgoing calls
no test coverage detected