Options
All
  • Public
  • Public/Protected
  • All
Menu

Module item-queue

Index

Type aliases

ItemQueueData

ItemQueueData<ItemT>: { _control?: symbol; item: ItemT; promise?: Promise<unknown>; stopOnError?: boolean }

data passed to the event handlers

Type parameters

  • ItemT = unknown

Type declaration

  • Optional _control?: symbol
  • item: ItemT
  • Optional promise?: Promise<unknown>
  • Optional stopOnError?: boolean

ItemQueueHandler

ItemQueueHandler<ItemT>: (data: ItemQueueResult<ItemT>) => void

Type parameters

  • ItemT = unknown

Type declaration

ItemQueueHandlers

ItemQueueHandlers<ItemT>: { doneItem?: ItemQueueHandler<ItemT>; fail?: ItemQueueHandler<ItemT>; failItem?: ItemQueueHandler<ItemT>; done?: any; empty?: any; pause?: any; watch?: any }

handlers for the events item queue emits

  • You can pass these to the queue in options.handlers
  • or you can handle each one as an event with queue.on

Type parameters

  • ItemT = unknown

Type declaration

  • Optional doneItem?: ItemQueueHandler<ItemT>

    an item was processed

  • Optional fail?: ItemQueueHandler<ItemT>

    queue failed

  • Optional failItem?: ItemQueueHandler<ItemT>

    an item processing failed

  • done: function
    • done(data: { endTime: number; startTime: number; totalTime: number }): void
    • queue finished

      • queue will emit an empty before this

      Parameters

      • data: { endTime: number; startTime: number; totalTime: number }
        • endTime: number
        • startTime: number
        • totalTime: number

      Returns void

  • empty: function
    • empty(): void
  • pause: function
    • pause(): void
  • watch: function
    • progress watcher that watch for items taking longer than options.watchTime to process.

      • If the queue emitted a watch event, and then all items resolved, it will emit the event one last time with empty items.

      Parameters

      Returns void

ItemQueueOptions

ItemQueueOptions<ItemT>: { Promise?: PromiseConstructor; concurrency?: number; handlers?: ItemQueueHandlers<ItemT>; itemQ?: ItemT[]; processItem: ProcessCb<ItemT>; stopOnError?: boolean; timeout?: number; watchPeriod?: number; watchTime?: number }

Item queue options

Type parameters

  • ItemT = unknown

Type declaration

  • Optional Promise?: PromiseConstructor

    pass in custom promise implementation

  • Optional concurrency?: number

    number of to process concurrently

  • Optional handlers?: ItemQueueHandlers<ItemT>

    event handlers

  • Optional itemQ?: ItemT[]

    initial array of items

  • processItem: ProcessCb<ItemT>

    callback to process each item

  • Optional stopOnError?: boolean

    immediately stop if an error occurred

  • Optional timeout?: number
  • Optional watchPeriod?: number

    frequency the progress watcher should check for overdue items

  • Optional watchTime?: number

    The time an item has to take before reporting it to the progress watcher

    • If an item is already overdue but has not trigger the watchTime again yet, then it's report as part of the still items in the WatchData.

ItemQueueResult

ItemQueueResult<ItemT>: ItemQueueData<ItemT> & { error?: Error; id: number; res?: ItemT }

result of processed an item

Type parameters

  • ItemT = unknown

ProcessCb

ProcessCb<ItemT>: (item: ItemT, id?: number) => Promise<unknown> | void

Type parameters

  • ItemT

Type declaration

    • (item: ItemT, id?: number): Promise<unknown> | void
    • Callback to process an item from the item queue

      Parameters

      • item: ItemT

        item to process

      • Optional id: number

        id number item queue uses to track this item

      Returns Promise<unknown> | void

WatchData

WatchData<ItemT>: { still: WatchItemInfo<ItemT>[]; total: number; watchTime: number; watched: WatchItemInfo<ItemT>[] }

Data for the progress watch event of overdue items that took longer than options.watchTime

The overdue items are reported in two fields: watched and still. Typically watched would contain the items that are newly become overdue or again. If you are not interested in the difference, then just combine them with [].concat(watched, still).

  • watched are items that pass options.watchTime for the first time or again since they were last checked.
  • still are items already overdue by options.watchTime but have not again taken more time than options.watchTime yet.

Type parameters

  • ItemT = unknown

Type declaration

  • still: WatchItemInfo<ItemT>[]

    Items that are already overdue but have not again taken more time than options.watchTime yet

  • total: number

    total number of items triggered in watched and still combined

  • watchTime: number

    time an item has to take before it's reported

  • watched: WatchItemInfo<ItemT>[]

    Items that took over options.watchTime for the first time or again since they were last checked

WatchItemInfo

WatchItemInfo<ItemT>: { item: ItemT; promise: Promise<unknown>; time: number }

Data of each item for the progress watch event

Type parameters

  • ItemT = unknown

Type declaration

  • item: ItemT

    item that made progress

  • promise: Promise<unknown>

    promise waiting for item

  • time: number

    time elapsed since item started processing

Generated using TypeDoc