Neolithic Prancing Minotaurs

    tail-queue
    TypeScript icon, indicating that this package has built-in type declarations

    1.0.9 • Public • Published

    tail-queue

    Globals

    tail-queue

    TypeScript/JavaScript promise queue client library with concurrency control

    Installation

    Install with npm:

    $ npm install --save tail-queue

    Install with yarn:

    $ yarn add tail-queue

    Demo

    Try online demo

    Documentation

    Try online documentation

    Classes

    tail-queue

    Globals / default

    Class: default<QueueType, EnqueueOptionsType>

    Promise queue with concurrency control.

    Type parameters

    Name Type Default
    QueueType Queue<RunFunction, EnqueueOptionsType> PriorityQueue
    EnqueueOptionsType QueueAddOptions DefaultAddOptions

    Hierarchy

    • EventEmitter

      default

    Index

    Constructors

    Properties

    Accessors

    Methods

    Constructors

    constructor

    + new default(options?: Options<QueueType, EnqueueOptionsType>): default

    Defined in src/index.ts:37

    Parameters:
    Name Type
    options? Options<QueueType, EnqueueOptionsType>

    Returns: default

    Properties

    defaultMaxListeners

    Static defaultMaxListeners: number

    Inherited from default.defaultMaxListeners

    Defined in node_modules/@types/events/index.d.ts:11

    Accessors

    concurrency

    • get concurrency(): number

    Defined in src/index.ts:215

    Returns: number

    • set concurrency(newConcurrency: number): void

    Defined in src/index.ts:219

    Parameters:
    Name Type
    newConcurrency number

    Returns: void


    isPaused

    • get isPaused(): boolean

    Defined in src/index.ts:395

    Whether the queue is currently paused.

    Returns: boolean


    pending

    • get pending(): number

    Defined in src/index.ts:388

    Number of pending promises.

    Returns: number


    size

    • get size(): number

    Defined in src/index.ts:372

    Size of the queue.

    Returns: number


    timeout

    • get timeout(): number | undefined

    Defined in src/index.ts:399

    Set the timeout for future operations.

    Returns: number | undefined

    • set timeout(milliseconds: number | undefined): void

    Defined in src/index.ts:406

    Set the timeout for future operations.

    Parameters:
    Name Type
    milliseconds number | undefined

    Returns: void

    Methods

    add

    add<TaskResultType>(fn: Task<TaskResultType>, options: Partial<EnqueueOptionsType>): Promise<TaskResultType>

    Defined in src/index.ts:234

    Adds a sync or async task to the queue. Always returns a promise.

    Type parameters:
    Name
    TaskResultType
    Parameters:
    Name Type Default value
    fn Task<TaskResultType> -
    options Partial<EnqueueOptionsType> {}

    Returns: Promise<TaskResultType>


    addAll

    addAll<TaskResultsType>(functions: ReadonlyArray<Task<TaskResultsType>>, options?: EnqueueOptionsType): Promise<TaskResultsType[]>

    Defined in src/index.ts:285

    Same as .add(), but accepts an array of sync or async functions.

    Type parameters:
    Name
    TaskResultsType
    Parameters:
    Name Type
    functions ReadonlyArray<Task<TaskResultsType>>
    options? EnqueueOptionsType

    Returns: Promise<TaskResultsType[]>

    A promise that resolves when all functions are resolved.


    addListener

    addListener(type: string | number, listener: Listener): this

    Inherited from default.addListener

    Defined in node_modules/@types/events/index.d.ts:17

    Parameters:
    Name Type
    type string | number
    listener Listener

    Returns: this


    clear

    clear(): void

    Defined in src/index.ts:323

    Clear the queue.

    Returns: void


    emit

    emit(type: string | number, ...args: any[]): boolean

    Inherited from default.emit

    Defined in node_modules/@types/events/index.d.ts:16

    Parameters:
    Name Type
    type string | number
    ...args any[]

    Returns: boolean


    eventNames

    eventNames(): Array<string | number>

    Inherited from default.eventNames

    Defined in node_modules/@types/events/index.d.ts:13

    Returns: Array<string | number>


    getMaxListeners

    getMaxListeners(): number

    Inherited from default.getMaxListeners

    Defined in node_modules/@types/events/index.d.ts:15

    Returns: number


    listenerCount

    listenerCount(type: string | number): number

    Inherited from default.listenerCount

    Defined in node_modules/@types/events/index.d.ts:26

    Parameters:
    Name Type
    type string | number

    Returns: number


    listeners

    listeners(type: string | number): Listener[]

    Inherited from default.listeners

    Defined in node_modules/@types/events/index.d.ts:25

    Parameters:
    Name Type
    type string | number

    Returns: Listener[]


    off

    off(type: string | number, listener: Listener): this

    Inherited from default.off

    Defined in node_modules/@types/events/index.d.ts:23

    Parameters:
    Name Type
    type string | number
    listener Listener

    Returns: this


    on

    on(type: string | number, listener: Listener): this

    Inherited from default.on

    Defined in node_modules/@types/events/index.d.ts:18

    Parameters:
    Name Type
    type string | number
    listener Listener

    Returns: this


    onEmpty

    onEmpty(): Promise<void>

    Defined in src/index.ts:332

    Can be called multiple times. Useful if you for example add additional items at a later time.

    Returns: Promise<void>

    A promise that settles when the queue becomes empty.


    onIdle

    onIdle(): Promise<void>

    Defined in src/index.ts:353

    The difference with .onEmpty is that .onIdle guarantees that all work from the queue has finished. .onEmpty merely signals that the queue is empty, but it could mean that some promises haven't completed yet.

    Returns: Promise<void>

    A promise that settles when the queue becomes empty, and all promises have completed; queue.size === 0 && queue.pending === 0.


    once

    once(type: string | number, listener: Listener): this

    Inherited from default.once

    Defined in node_modules/@types/events/index.d.ts:19

    Parameters:
    Name Type
    type string | number
    listener Listener

    Returns: this


    pause

    pause(): void

    Defined in src/index.ts:316

    Put queue execution on hold.

    Returns: void


    prependListener

    prependListener(type: string | number, listener: Listener): this

    Inherited from default.prependListener

    Defined in node_modules/@types/events/index.d.ts:20

    Parameters:
    Name Type
    type string | number
    listener Listener

    Returns: this


    prependOnceListener

    prependOnceListener(type: string | number, listener: Listener): this

    Inherited from default.prependOnceListener

    Defined in node_modules/@types/events/index.d.ts:21

    Parameters:
    Name Type
    type string | number
    listener Listener

    Returns: this


    rawListeners

    rawListeners(type: string | number): Listener[]

    Inherited from default.rawListeners

    Defined in node_modules/@types/events/index.d.ts:27

    Parameters:
    Name Type
    type string | number

    Returns: Listener[]


    removeAllListeners

    removeAllListeners(type?: string | number): this

    Inherited from default.removeAllListeners

    Defined in node_modules/@types/events/index.d.ts:24

    Parameters:
    Name Type
    type? string | number

    Returns: this


    removeListener

    removeListener(type: string | number, listener: Listener): this

    Inherited from default.removeListener

    Defined in node_modules/@types/events/index.d.ts:22

    Parameters:
    Name Type
    type string | number
    listener Listener

    Returns: this


    setMaxListeners

    setMaxListeners(n: number): this

    Inherited from default.setMaxListeners

    Defined in node_modules/@types/events/index.d.ts:14

    Parameters:
    Name Type
    n number

    Returns: this


    sizeBy

    sizeBy(options: Readonly<Partial<EnqueueOptionsType>>): number

    Defined in src/index.ts:381

    Size of the queue, filtered by the given options.

    For example, this can be used to find the number of items remaining in the queue with a specific priority level.

    Parameters:
    Name Type
    options Readonly<Partial<EnqueueOptionsType>>

    Returns: number


    start

    start(): this

    Defined in src/index.ts:301

    Start (or resume) executing enqueued tasks within concurrency limit. No need to call this if queue is not paused (via options.autoStart = false or by .pause() method.)

    Returns: this


    listenerCount

    StaticlistenerCount(emitter: EventEmitter, type: string | number): number

    Inherited from default.listenerCount

    Defined in node_modules/@types/events/index.d.ts:10

    Parameters:
    Name Type
    emitter EventEmitter
    type string | number

    Returns: number

    tail-queue

    Globals / PriorityQueue

    Class: PriorityQueue

    Hierarchy

    • PriorityQueue

    Implements

    Index

    Accessors

    Methods

    Accessors

    size

    • get size(): number

    Defined in src/priority-queue.ts:60

    Returns: number

    Methods

    dequeue

    dequeue(): RunFunction | undefined

    Defined in src/priority-queue.ts:45

    Returns: RunFunction | undefined


    enqueue

    enqueue(run: RunFunction, options?: Partial<PriorityQueueOptions>): void

    Defined in src/priority-queue.ts:13

    Parameters:
    Name Type
    run RunFunction
    options? Partial<PriorityQueueOptions>

    Returns: void


    filter

    filter(options: Readonly<Partial<PriorityQueueOptions>>): RunFunction[]

    Defined in src/priority-queue.ts:49

    Parameters:
    Name Type
    options Readonly<Partial<PriorityQueueOptions>>

    Returns: RunFunction[]

    tail-queue

    Globals

    tail-queue

    Index

    Classes

    Interfaces

    Type aliases

    Functions

    Type aliases

    ResolveFunction

    Ƭ ResolveFunction<T>: (value?: T | PromiseLike<T>) => void

    Defined in src/types.ts:9

    Type parameters:

    Name Default
    T void

    RunFunction

    Ƭ RunFunction: () => Promise<unknown>

    Defined in src/types.ts:8


    Task

    Ƭ Task<TaskResultType>: () => PromiseLike<TaskResultType> | () => TaskResultType

    Defined in src/types.ts:10

    Type parameters:

    Name
    TaskResultType

    Functions

    PromiseFinally

    PromiseFinally<T>(promise: T, fallback: any): Promise<T>

    Defined in src/utils.ts:1

    Type parameters:

    Name Default
    T any

    Parameters:

    Name Type
    promise T
    fallback any

    Returns: Promise<T>


    PromiseTimeout

    PromiseTimeout(promise: any, milliseconds: number, fallback: any): Promise<any>

    Defined in src/utils.ts:18

    Parameters:

    Name Type
    promise any
    milliseconds number
    fallback any

    Returns: Promise<any>


    empty

    Constempty(): void

    Defined in src/utils.ts:83

    Returns: void


    lowerBound

    lowerBound<T>(array: readonly T[], value: T, comparator: (a: T,b: T) => number): number

    Defined in src/utils.ts:60

    Type parameters:

    Name
    T

    Parameters:

    Name Type
    array readonly T[]
    value T
    comparator (a: T,b: T) => number

    Returns: number

    Interfaces

    tail-queue

    Globals / DefaultAddOptions

    Interface: DefaultAddOptions

    Hierarchy

    Indexable

    ▪ [key: string]: unknown

    Index

    Properties

    Properties

    priority

    Optional Readonly priority: undefined | number

    Defined in src/options.ts:72

    Priority of operation. Operations with greater priority will be scheduled first.

    default 0

    tail-queue

    Globals / Options

    Interface: Options<QueueType, QueueOptions>

    Type parameters

    Name Type
    QueueType Queue<RunFunction, QueueOptions>
    QueueOptions QueueAddOptions

    Hierarchy

    • Options

    Index

    Properties

    Properties

    autoStart

    Optional Readonly autoStart: undefined | false | true

    Defined in src/options.ts:21

    Whether queue tasks within concurrency limit, are auto-executed as soon as they're added.

    default true


    carryoverConcurrencyCount

    Optional Readonly carryoverConcurrencyCount: undefined | false | true

    Defined in src/options.ts:51

    Whether the task must finish in the given interval or will be carried over into the next interval count.

    default false


    concurrency

    Optional Readonly concurrency: undefined | number

    Defined in src/options.ts:14

    Concurrency limit.

    Minimum: 1.

    default Infinity


    interval

    Optional Readonly interval: undefined | number

    Defined in src/options.ts:44

    The length of time in milliseconds before the interval count resets. Must be finite.

    Minimum: 0.

    default 0


    intervalCap

    Optional Readonly intervalCap: undefined | number

    Defined in src/options.ts:35

    The max number of runs in the given interval of time.

    Minimum: 1.

    default Infinity


    queueClass

    Optional Readonly queueClass: undefined | {}

    Defined in src/options.ts:26

    Class with a enqueue and dequeue method, and a size getter. See the Custom QueueClass section.


    throwOnTimeout

    Optional throwOnTimeout: undefined | false | true

    Defined in src/options.ts:63

    Whether or not a timeout is considered an exception.

    default false


    timeout

    Optional timeout: undefined | number

    Defined in src/options.ts:56

    Per-operation timeout in milliseconds. Operations fulfill once timeout elapses if they haven't already.

    tail-queue

    Globals / PriorityQueueOptions

    Interface: PriorityQueueOptions

    Hierarchy

    Indexable

    ▪ [key: string]: unknown

    Index

    Properties

    Properties

    priority

    Optional priority: undefined | number

    Defined in src/types.ts:19

    tail-queue

    Globals / PriorityQueueRunOptions

    Interface: PriorityQueueRunOptions

    Hierarchy

    Indexable

    ▪ [key: string]: unknown

    Index

    Properties

    Properties

    priority

    Optional priority: undefined | number

    Inherited from PriorityQueueOptions.priority

    Defined in src/types.ts:19


    run

    run: RunFunction

    Defined in src/types.ts:23

    tail-queue

    Globals / Queue

    Interface: Queue<Element, Options>

    Type parameters

    Name
    Element
    Options

    Hierarchy

    • Queue

    Implemented by

    Index

    Properties

    Properties

    dequeue

    dequeue: () => Element | undefined

    Defined in src/types.ts:4


    enqueue

    enqueue: (run: Element,options?: Partial<Options>) => void

    Defined in src/types.ts:5


    filter

    filter: (options: Partial<Options>) => Element[]

    Defined in src/types.ts:3


    size

    size: number

    Defined in src/types.ts:2

    tail-queue

    Globals / QueueAddOptions

    Interface: QueueAddOptions

    Hierarchy

    Indexable

    ▪ [key: string]: unknown

    Install

    npm i tail-queue

    DownloadsWeekly Downloads

    1

    Version

    1.0.9

    License

    Apache-2.0

    Unpacked Size

    118 kB

    Total Files

    25

    Last publish

    Collaborators

    • dimetrix