Skip to content

TQueue

34 exports Added in v2.0.0 Source

Constructors

bounded

Added in v2.0.0 Source

Creates a bounded queue with the back pressure strategy. The queue will retain values until they have been taken, applying back pressure to offerors if the queue is at capacity.

For best performance use capacities that are powers of two.

Signature

declare const bounded: <A>(requestedCapacity: number) => STM.STM<TQueue<A>>;

dropping

Added in v2.0.0 Source

Creates a bounded queue with the dropping strategy. The queue will drop new values if the queue is at capacity.

For best performance use capacities that are powers of two.

Signature

declare const dropping: <A>(requestedCapacity: number) => STM.STM<TQueue<A>>;

sliding

Added in v2.0.0 Source

Creates a bounded queue with the sliding strategy. The queue will add new values and drop old values if the queue is at capacity.

For best performance use capacities that are powers of two.

Signature

declare const sliding: <A>(requestedCapacity: number) => STM.STM<TQueue<A>>;

unbounded

Added in v2.0.0 Source

Creates an unbounded queue.

Signature

declare const unbounded: <A>() => STM.STM<TQueue<A>>;

Getters

capacity

Added in v2.0.0 Source

Returns the number of elements the queue can hold.

Signature

declare const capacity: <A>(self: TDequeue<A> | TEnqueue<A>) => number;

isEmpty

Added in v2.0.0 Source

Returns true if the TQueue contains zero elements, false otherwise.

Signature

declare const isEmpty: <A>(self: TDequeue<A> | TEnqueue<A>) => STM.STM<boolean>;

isFull

Added in v2.0.0 Source

Returns true if the TQueue contains at least one element, false otherwise.

Signature

declare const isFull: <A>(self: TDequeue<A> | TEnqueue<A>) => STM.STM<boolean>;

isShutdown

Added in v2.0.0 Source

Returns true if shutdown has been called, otherwise returns false.

Signature

declare const isShutdown: <A>(self: TDequeue<A> | TEnqueue<A>) => STM.STM<boolean>;

peek

Added in v2.0.0 Source

Views the next element in the queue without removing it, retrying if the queue is empty.

Signature

declare const peek: <A>(self: TDequeue<A>) => STM.STM<A>;

peekOption

Added in v2.0.0 Source

Views the next element in the queue without removing it, returning None if the queue is empty.

Signature

declare const peekOption: <A>(self: TDequeue<A>) => STM.STM<Option.Option<A>>;

poll

Added in v2.0.0 Source

Takes a single element from the queue, returning None if the queue is empty.

Signature

declare const poll: <A>(self: TDequeue<A>) => STM.STM<Option.Option<A>>;

size

Added in v2.0.0 Source

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.

Signature

declare const size: <A>(self: TDequeue<A> | TEnqueue<A>) => STM.STM<number>;

Models

BaseTQueue interface

Added in v2.0.0 Source

The base interface that all TQueues must implement.

Signature

interface BaseTQueue {
  readonly awaitShutdown: STM<void>;
  readonly isEmpty: STM<boolean>;
  readonly isFull: STM<boolean>;
  readonly isShutdown: STM<boolean>;
  readonly shutdown: STM<void>;
  readonly size: STM<number>;
  capacity(): number;
}

TDequeue interface

Added in v2.0.0 Source

Signature

interface TDequeue<out A> extends TDequeueVariance<A>, BaseTQueue {
  readonly peek: STM<A>;
  readonly peekOption: STM<Option<A>>;
  readonly take: STM<A>;
  readonly takeAll: STM<Array<A>>;
  takeUpTo(max: number): STM<Array<A>>;
}

TEnqueue interface

Added in v2.0.0 Source

Signature

interface TEnqueue<in A> extends TEnqueueVariance<A>, BaseTQueue {
  offer(value: A): STM<boolean>;
  offerAll(iterable: Iterable<A>): STM<boolean>;
}

TQueue interface

Added in v2.0.0 Source

Signature

interface TQueue<in out A> extends TEnqueue<A>, TDequeue<A> {}

Mutations

Waits until the queue is shutdown. The STM returned by this method will not resume until the queue has been shutdown. If the queue is already shutdown, the STM will resume right away.

Signature

declare const awaitShutdown: <A>(self: TDequeue<A> | TEnqueue<A>) => STM.STM<void>;

offer

Added in v2.0.0 Source

Places one value in the queue.

Signature

declare const offer: {
  <A>(value: A): (self: TEnqueue<A>) => STM<void>;
  <A>(self: TEnqueue<A>, value: A): STM<void>;
};

offerAll

Added in v2.0.0 Source

For Bounded TQueue: uses the BackPressure Strategy, places the values in the queue and always returns true. If the queue has reached capacity, then the fiber performing the offerAll will be suspended until there is room in the queue.

For Unbounded TQueue: Places all values in the queue and returns true.

For Sliding TQueue: uses Sliding Strategy If there is room in the queue, it places the values otherwise it removes the old elements and enqueues the new ones. Always returns true.

For Dropping TQueue: uses Dropping Strategy, It places the values in the queue but if there is no room it will not enqueue them and return false.

Signature

declare const offerAll: {
  <A>(iterable: Iterable<A>): (self: TEnqueue<A>) => STM<boolean>;
  <A>(self: TEnqueue<A>, iterable: Iterable<A>): STM<boolean>;
};

seek

Added in v2.0.0 Source

Drops elements from the queue while they do not satisfy the predicate, taking and returning the first element that does satisfy the predicate. Retries if no elements satisfy the predicate.

Signature

declare const seek: {
  <A>(predicate: Predicate<A>): (self: TDequeue<A>) => STM<A>;
  <A>(self: TDequeue<A>, predicate: Predicate<A>): STM<A>;
};

shutdown

Added in v2.0.0 Source

Interrupts any fibers that are suspended on offer or take. Future calls to offer* and take* will be interrupted immediately.

Signature

declare const shutdown: <A>(self: TDequeue<A> | TEnqueue<A>) => STM.STM<void>;

take

Added in v2.0.0 Source

Takes the oldest value in the queue. If the queue is empty, this will return a computation that resumes when an item has been added to the queue.

Signature

declare const take: <A>(self: TDequeue<A>) => STM.STM<A>;

takeAll

Added in v2.0.0 Source

Takes all the values in the queue and returns the values. If the queue is empty returns an empty collection.

Signature

declare const takeAll: <A>(self: TDequeue<A>) => STM.STM<Array<A>>;

takeBetween

Added in v2.0.0 Source

Takes a number of elements from the queue between the specified minimum and maximum. If there are fewer than the minimum number of elements available, retries until at least the minimum number of elements have been collected.

Signature

declare const takeBetween: {
  (min: number, max: number): <A>(self: TDequeue<A>) => STM<Array<A>>;
  <A>(self: TDequeue<A>, min: number, max: number): STM<Array<A>>;
};

takeN

Added in v2.0.0 Source

Takes the specified number of elements from the queue. If there are fewer than the specified number of elements available, it retries until they become available.

Signature

declare const takeN: {
  (n: number): <A>(self: TDequeue<A>) => STM<Array<A>>;
  <A>(self: TDequeue<A>, n: number): STM<Array<A>>;
};

takeUpTo

Added in v2.0.0 Source

Takes up to max number of values from the queue.

Signature

declare const takeUpTo: {
  (max: number): <A>(self: TDequeue<A>) => STM<Array<A>>;
  <A>(self: TDequeue<A>, max: number): STM<Array<A>>;
};

Other

TQueue

Added in v2.0.0 Source

Refinements

isTDequeue

Added in v2.0.0 Source

Returns true if the specified value is a TDequeue, false otherwise.

Signature

declare const isTDequeue: (u: unknown) => u is TDequeue<unknown>;

isTEnqueue

Added in v2.0.0 Source

Returns true if the specified value is a TEnqueue, false otherwise.

Signature

declare const isTEnqueue: (u: unknown) => u is TEnqueue<unknown>;

isTQueue

Added in v2.0.0 Source

Returns true if the specified value is a TQueue, false otherwise.

Signature

declare const isTQueue: (u: unknown) => u is TQueue<unknown>;

Symbols

Signature

declare const TDequeueTypeId: unique symbol;

TDequeueTypeId type

Added in v2.0.0 Source

Signature

type TDequeueTypeId = typeof TDequeueTypeId;

Signature

declare const TEnqueueTypeId: unique symbol;

TEnqueueTypeId type

Added in v2.0.0 Source

Signature

type TEnqueueTypeId = typeof TEnqueueTypeId;