import { Synchronizer } from "../synchronizer.interface"; /** * A ProducerConsumer class to read and write data with synchronization. * * The queue is a simple FIFO (First In, First Out). */ export declare class ProducerConsumer implements Synchronizer { /** * The that will be read and write */ private readonly items; /** * The internal semaphore for synchronization */ private readonly semaphore; /** * @returns the current number of available items */ get itemsAvailable(): number; /** * @returns the minimal number of items needed to release all "threads" */ get itemsRequired(): number; /** * @returns the number of waiting "threads" on any read */ get queueLength(): number; /** * Create a ProducerConsumer * * @param initialItems the initial available values */ constructor(initialItems?: readonly T[]); /** * Reads a given number of items: * Wait until the given number of items are available. * * @param nItem the number of items to read * @throws {ProducerConsumerInvalidReadParameterException} when the number of items to read is invalid * @throws {ConcurrencyInterruptedException} when the producer-consumer is interrupted * @returns a promise with the read results */ read(nItem: number): Promise; /** * Reads one item: * Wait until the item is available. * * @throws {ConcurrencyInterruptedException} when the producer-consumer is interrupted * @returns a promise with the read results */ readOne(): Promise; /** * Reads a given number of items: * Wait until the given number of items are available. * * Throws an error if the given time exceeds * and re-establish the state as if the method was not called. * * @param timeout maximum time (in ms) to read the items * @param nItem the number of items to read * @throws {ProducerConsumerInvalidReadParameterException} when the number of items to read is invalid * @throws {ConcurrencyInterruptedException} when the producer-consumer is interrupted * @returns a promise with the read results */ tryRead(timeout: number, nItem: number): Promise; /** * Reads one item: * Wait until the item is available. * * Throws an error if the given time exceeds * and re-establish the state as if the method was not called. * * @param timeout maximum time (in ms) to read the items * @throws {ConcurrencyInterruptedException} when the producer-consumer is interrupted * @returns a promise with the read result */ tryReadOne(timeout: number): Promise; /** * Write some items to the producer-consumer buffer. * It releases the await readings or store the data for future readings. * * @param items the items to write */ write(...items: T[]): void; /** * Interrupts all awaiting "threads" with an [exception]{@link ConcurrencyInterruptedException}. * * @param reason The reason why this producer-consumer is being interrupted * @param items the items to set once everything has been interrupted */ interrupt(reason: unknown, items?: readonly T[]): void; }