/**
* @since 1.0.0
*/
import type { Pipeable } from "@effect/data/Pipeable"
import type * as Effect from "@effect/io/Effect"
import * as internal from "@effect/io/internal/hub"
import type * as Queue from "@effect/io/Queue"
import type * as Scope from "@effect/io/Scope"
/**
* A `Hub` is an asynchronous message hub into which publishers can publish
* messages of type `A` and subscribers can subscribe to take messages of type
* `A`.
*
* @since 1.0.0
* @category models
*/
export interface Hub extends Queue.Enqueue, Pipeable {
/**
* Publishes a message to the hub, returning whether the message was published
* to the hub.
*/
publish(value: A): Effect.Effect
/**
* Publishes all of the specified messages to the hub, returning whether they
* were published to the hub.
*/
publishAll(elements: Iterable): Effect.Effect
/**
* Subscribes to receive messages from the hub. The resulting subscription can
* be evaluated multiple times within the scope to take a message from the hub
* each time.
*/
subscribe(): Effect.Effect>
}
/**
* Creates a bounded hub with the back pressure strategy. The hub will retain
* messages until they have been taken by all subscribers, applying back
* pressure to publishers if the hub is at capacity.
*
* For best performance use capacities that are powers of two.
*
* @since 1.0.0
* @category constructors
*/
export const bounded: (requestedCapacity: number) => Effect.Effect> = internal.bounded
/**
* Creates a bounded hub with the dropping strategy. The hub will drop new
* messages if the hub is at capacity.
*
* For best performance use capacities that are powers of two.
*
* @since 1.0.0
* @category constructors
*/
export const dropping: (requestedCapacity: number) => Effect.Effect> = internal.dropping
/**
* Creates a bounded hub with the sliding strategy. The hub will add new
* messages and drop old messages if the hub is at capacity.
*
* For best performance use capacities that are powers of two.
*
* @since 1.0.0
* @category constructors
*/
export const sliding: (requestedCapacity: number) => Effect.Effect> = internal.sliding
/**
* Creates an unbounded hub.
*
* @since 1.0.0
* @category constructors
*/
export const unbounded: () => Effect.Effect> = internal.unbounded
/**
* Returns the number of elements the queue can hold.
*
* @since 1.0.0
* @category getters
*/
export const capacity: (self: Hub) => number = internal.capacity
/**
* Retrieves the size of the queue, which is equal to the number of elements
* in the queue. This may be negative if fibers are suspended waiting for
* elements to be added to the queue.
*
* @since 1.0.0
* @category getters
*/
export const size: (self: Hub) => Effect.Effect = internal.size
/**
* Returns `true` if the `Queue` contains at least one element, `false`
* otherwise.
*
* @since 1.0.0
* @category getters
*/
export const isFull: (self: Hub) => Effect.Effect = internal.isFull
/**
* Returns `true` if the `Queue` contains zero elements, `false` otherwise.
*
* @since 1.0.0
* @category getters
*/
export const isEmpty: (self: Hub) => Effect.Effect = internal.isEmpty
/**
* Interrupts any fibers that are suspended on `offer` or `take`. Future calls
* to `offer*` and `take*` will be interrupted immediately.
*
* @since 1.0.0
* @category utils
*/
export const shutdown: (self: Hub) => Effect.Effect = internal.shutdown
/**
* Returns `true` if `shutdown` has been called, otherwise returns `false`.
*
* @since 1.0.0
* @category getters
*/
export const isShutdown: (self: Hub) => Effect.Effect = internal.isShutdown
/**
* Waits until the queue is shutdown. The `Effect` returned by this method will
* not resume until the queue has been shutdown. If the queue is already
* shutdown, the `Effect` will resume right away.
*
* @since 1.0.0
* @category utils
*/
export const awaitShutdown: (self: Hub) => Effect.Effect = internal.awaitShutdown
/**
* Publishes a message to the hub, returning whether the message was published
* to the hub.
*
* @since 1.0.0
* @category utils
*/
export const publish: {
(value: A): (self: Hub) => Effect.Effect
(self: Hub, value: A): Effect.Effect
} = internal.publish
/**
* Publishes all of the specified messages to the hub, returning whether they
* were published to the hub.
*
* @since 1.0.0
* @category utils
*/
export const publishAll: {
(elements: Iterable): (self: Hub) => Effect.Effect
(self: Hub, elements: Iterable): Effect.Effect
} = internal.publishAll
/**
* Subscribes to receive messages from the hub. The resulting subscription can
* be evaluated multiple times within the scope to take a message from the hub
* each time.
*
* @since 1.0.0
* @category utils
*/
export const subscribe: (self: Hub) => Effect.Effect> = internal.subscribe