UNPKG

@buttercup/channel-queue

Version:

A queue management library with channels

46 lines (45 loc) 1.56 kB
import { EventEmitter } from "eventemitter3"; import { Channel } from "./Channel"; import { ParallelChannel } from "./ParallelChannel"; /** * ChannelQueue class, for managing channels * @augments EventEmitter */ export declare class ChannelQueue extends EventEmitter { private _channels; constructor(); /** * The channels * @type {Object} */ get channels(): Record<string, Channel | ParallelChannel>; /** * Create a new channel * @param {String} name The channel name * @returns {Channel} The new channel * @throws {Error} Throws if the channel already exists */ createChannel(name: string): Channel; /** * Create a new parallel channel * Creates a special channel that supports running several tasks in parallel. * @param {String} name The name of the channel * @param {Number=} parallelism Optional number of maximum parallel tasks * @returns {ParallelChannel} The new channel * @throws {Error} Throws if the channel already exists */ createParallelChannel(name: string, parallelism?: number): ParallelChannel; /** * Get channel by name * Creates a new channel automatically if it doesn't yet exist * @param {String} name The channel name * @returns {Channel} The channel which was requested */ channel(name: string): Channel; /** * Check if a channel exists * @param {String} name The name of the channel * @returns {Boolean} True if it exists */ channelExists(name: string): boolean; }