import { MutableHashSet } from "@tsplus/stdlib/collections/mutable/MutableHashSet/definition";
import { MutableQueue } from "@tsplus/stdlib/collections/mutable/MutableQueue/definition";
import { Deferred } from "@effect/core/io/Deferred/definition";
import { Collection } from "@tsplus/stdlib/collections/Collection/definition";
import { AtomicBoolean } from "@tsplus/stdlib/data/AtomicBoolean";
import { Effect } from "@effect/core/io/Effect/definition";
import { EmptyMutableQueue } from "@tsplus/stdlib/collections/mutable/MutableQueue";
import type { AtomicHub } from "@effect/core/io/Hub/operations/_internal/AtomicHub";
import type { Subscription } from "@effect/core/io/Hub/operations/_internal/Subscription";
/**
* A `Strategy` describes the protocol for how publishers and subscribers
* will communicate with each other through the hub.
*
* @tsplus type effect/core/io/Hub/Strategy
*/
export interface Strategy {
/**
* Describes how publishers should signal to subscribers that they are
* waiting for space to become available in the hub.
*/
readonly handleSurplus: (hub: AtomicHub, subscribers: MutableHashSet, MutableQueue>]>, as: Collection, isShutdown: AtomicBoolean) => Effect;
/**
* Describes any finalization logic associated with this strategy.
*/
readonly shutdown: Effect;
/**
* Describes how subscribers should signal to publishers waiting for space
* to become available in the hub that space may be available.
*/
readonly unsafeOnHubEmptySpace: (hub: AtomicHub, subscribers: MutableHashSet, MutableQueue>]>) => void;
/**
* Describes how subscribers waiting for additional values from the hub
* should take those values and signal to publishers that they are no
* longer waiting for additional values.
*/
readonly unsafeCompletePollers: (hub: AtomicHub, subscribers: MutableHashSet, MutableQueue>]>, subscription: Subscription, pollers: MutableQueue>) => void;
/**
* Describes how publishers should signal to subscribers waiting for
* additional values from the hub that new values are available.
*/
readonly unsafeCompleteSubscribers: (hub: AtomicHub, subscribers: MutableHashSet, MutableQueue>]>) => void;
}
/**
* @tsplus type effect/core/io/Hub/Strategy.Ops
*/
export interface StrategyOps {
}
export declare const Strategy: StrategyOps;
declare abstract class BaseStrategy implements Strategy {
abstract handleSurplus(hub: AtomicHub, subscribers: MutableHashSet, MutableQueue>]>, as: Collection, isShutdown: AtomicBoolean): Effect;
abstract shutdown: Effect;
abstract unsafeOnHubEmptySpace(hub: AtomicHub, subscribers: MutableHashSet, MutableQueue>]>): void;
unsafeCompletePollers(hub: AtomicHub, subscribers: MutableHashSet, MutableQueue>]>, subscription: Subscription, pollers: MutableQueue>): void;
unsafeCompleteSubscribers(hub: AtomicHub, subscribers: MutableHashSet, MutableQueue>]>): void;
}
/**
* A strategy that applies back pressure to publishers when the hub is at
* capacity. This guarantees that all subscribers will receive all messages
* published to the hub while they are subscribed. However, it creates the
* risk that a slow subscriber will slow down the rate at which messages
* are published and received by other subscribers.
*/
export declare class BackPressure extends BaseStrategy {
publishers: MutableQueue, boolean]>;
handleSurplus(hub: AtomicHub, subscribers: MutableHashSet, MutableQueue>]>, as: Collection, isShutdown: AtomicBoolean): Effect;
get shutdown(): Effect;
unsafeOnHubEmptySpace(hub: AtomicHub, subscribers: MutableHashSet, MutableQueue>]>): void;
private unsafeOffer;
private unsafeRemove;
}
/**
* A strategy that drops new messages when the hub is at capacity. This
* guarantees that a slow subscriber will not slow down the rate at which
* messages are published. However, it creates the risk that a slow
* subscriber will slow down the rate at which messages are received by
* other subscribers and that subscribers may not receive all messages
* published to the hub while they are subscribed.
*/
export declare class Dropping extends BaseStrategy {
handleSurplus(_hub: AtomicHub, _subscribers: MutableHashSet, MutableQueue>]>, _as: Collection, _isShutdown: AtomicBoolean): Effect;
shutdown: Effect;
unsafeOnHubEmptySpace(_hub: AtomicHub, _subscribers: MutableHashSet, MutableQueue>]>): void;
}
/**
* A strategy that adds new messages and drops old messages when the hub is
* at capacity. This guarantees that a slow subscriber will not slow down
* the rate at which messages are published and received by other
* subscribers. However, it creates the risk that a slow subscriber will
* not receive some messages published to the hub while it is subscribed.
*/
export declare class Sliding extends BaseStrategy {
private unsafeSlidingPublish;
handleSurplus(hub: AtomicHub, subscribers: MutableHashSet, MutableQueue>]>, as: Collection, _isShutdown: AtomicBoolean): Effect;
shutdown: Effect;
unsafeOnHubEmptySpace(_hub: AtomicHub, _subscribers: MutableHashSet, MutableQueue>]>): void;
}
/**
* @tsplus static effect/core/io/Hub/Strategy.Ops BackPressure
* @tsplus location "@effect/core/io/Hub/operations/strategy"
*/
export declare function backPressureStrategy(): Strategy;
/**
* @tsplus static effect/core/io/Hub/Strategy.Ops Dropping
* @tsplus location "@effect/core/io/Hub/operations/strategy"
*/
export declare function droppingStrategy(): Strategy;
/**
* @tsplus static effect/core/io/Hub/Strategy.Ops Sliding
* @tsplus location "@effect/core/io/Hub/operations/strategy"
*/
export declare function slidingStrategy(): Strategy;
export {};
//# sourceMappingURL=strategy.d.ts.map