TxPriorityQueue
Transactional priority queues whose state is stored in a TxRef. Elements are kept in the order defined by the Order supplied at construction time, and dequeue operations return the first element according to that ordering.
Use TxPriorityQueue when multiple fibers coordinate through a shared queue and queue operations need to compose with other transactional state changes. The retrying peek and take operations wait transactionally when the queue is empty, so they can be combined with other transactional reads and writes in one atomic workflow.
Constructors
Signature
declare function empty<A>(order: Order<A>): Effect<TxPriorityQueue<A>>;fromIterable
Creates a TxPriorityQueue from an iterable of elements.
Signature
declare const fromIterable: {
<A>(order: Order<A>): (iterable: Iterable<A>) => Effect<TxPriorityQueue<A>>;
<A>(order: Order<A>, iterable: Iterable<A>): Effect<TxPriorityQueue<A>>;
};Creates a TxPriorityQueue from variadic elements.
Signature
declare function make<A>(order: Order<A>): (...elements: Array<A>) => Effect<TxPriorityQueue<A>>;Converting
Filtering
Removes elements matching the predicate.
Signature
declare const removeIf: {
<A>(predicate: Predicate<A>): (self: TxPriorityQueue<A>) => Effect<void>;
<A>(self: TxPriorityQueue<A>, predicate: Predicate<A>): Effect<void>;
};Keeps only elements matching the predicate.
Signature
declare const retainIf: {
<A>(predicate: Predicate<A>): (self: TxPriorityQueue<A>) => Effect<void>;
<A>(self: TxPriorityQueue<A>, predicate: Predicate<A>): Effect<void>;
};Getters
Observes the smallest element without removing it.
When to use
Use to inspect the next prioritized value and retry transactionally while the queue is empty.
Signature
declare function peek<A>(self: TxPriorityQueue<A>): Effect<A>;peekOption
Observes the smallest element without removing it, returning None when the queue is empty.
When to use
Use to inspect the next prioritized value without retrying on an empty queue.
Signature
declare function peekOption<A>(self: TxPriorityQueue<A>): Effect<Option<A>>;Returns the number of elements in the queue.
Signature
declare function size<A>(self: TxPriorityQueue<A>): Effect<number>;Guards
isTxPriorityQueue
Determines if the provided value is a TxPriorityQueue.
Signature
declare function isTxPriorityQueue(u: unknown): u is TxPriorityQueue<unknown>;Models
TxPriorityQueue interface
A transactional priority queue backed by a sorted Chunk.
Details
Elements are stored in ascending order according to the Order provided at construction time. take returns the smallest element, peek observes it without removing.
Signature
interface TxPriorityQueue<in out A> extends Inspectable, Pipeable {
readonly "~effect/transactions/TxPriorityQueue": "~effect/transactions/TxPriorityQueue";
readonly ord: Order<A>;
readonly ref: TxRef<Chunk<A>>;
}Mutations
Inserts an element into the queue in sorted position.
Signature
declare const offer: {
<A>(value: A): (self: TxPriorityQueue<A>) => Effect<void>;
<A>(self: TxPriorityQueue<A>, value: A): Effect<void>;
};Inserts all elements from an iterable into the queue.
Signature
declare const offerAll: {
<A>(values: Iterable<A>): (self: TxPriorityQueue<A>) => Effect<void>;
<A>(self: TxPriorityQueue<A>, values: Iterable<A>): Effect<void>;
};Takes the smallest element from the queue. Retries if the queue is empty.
Signature
declare function take<A>(self: TxPriorityQueue<A>): Effect<A>;Takes all elements from the queue, returning them in priority order.
Signature
declare function takeAll<A>(self: TxPriorityQueue<A>): Effect<Array<A>>;takeOption
Tries to take the smallest element. Returns None if the queue is empty.
Signature
declare function takeOption<A>(self: TxPriorityQueue<A>): Effect<Option<A>>;Takes up to n elements from the queue in priority order.
Signature
declare const takeUpTo: {
(n: number): <A>(self: TxPriorityQueue<A>) => Effect<Array<A>>;
<A>(self: TxPriorityQueue<A>, n: number): Effect<Array<A>>;
};Predicates
Returns true if the queue is empty.
Signature
declare function isEmpty<A>(self: TxPriorityQueue<A>): Effect<boolean>;isNonEmpty
Returns true if the queue has at least one element.
Signature
declare function isNonEmpty<A>(self: TxPriorityQueue<A>): Effect<boolean>;
Creates an empty
TxPriorityQueuewith the given ordering.