Options
All
  • Public
  • Public/Protected
  • All
Menu

Class TaskQueue

A Pull-TaskQueue sorted by priority and group-able Tasks by Task.group.

remarks
example

Sample Usage

 const taskQueue = new TaskQueue({
     group: ["group1"]
 })
 taskQueue.add({
    group: "group1",
    execute: () => {
        console.log("task of group1 executed");
    },
    getPrio: () => {
        return 0;
    }
  });

taskQueue.update();
taskQueue.processNext("group1");

Hierarchy

  • TaskQueue

Index

Constructors

constructor

Methods

add

  • add(task: Task): boolean

clear

  • clear(): void

numItemsLeft

  • numItemsLeft(group?: undefined | string): number
  • Returns the number of remaining tasks.

    Parameters

    • Optional group: undefined | string

      if group is set, it will return only the remaining tasks for this group, otherwise it will return the complete amount of tasks left.

    Returns number

processNext

  • processNext(group: string, shouldProcess?: undefined | ((task: Task) => boolean), n?: number): boolean
  • Processes the next Tasks for a group

    Parameters

    • group: string

      The group the Tasks are pulled from.

    • Optional shouldProcess: undefined | ((task: Task) => boolean)

      A condition that, if set will be executed before the task is processed, if returns true, the task will run

    • Default value n: number = 1

      The amount of tasks that should be pulled, @defaults to 1

    Returns boolean

    false if thte list was empty

remove

  • remove(task: Task): boolean

update

  • update(group?: undefined | string): void
  • Updates the lists in the queue depending on their priority functions and removes expired Tasks, based on their isExpired functions result.

    Parameters

    • Optional group: undefined | string

      The Group to update, if not set all groups will be updated.

    Returns void

Generated using TypeDoc