oolymer / oo-worker

Polymer mixin to process batches of tasks sorted by priority.
MIT License
0 stars 0 forks source link

(feature) Problem: Defining the order in which tasks are dequeued is impossible. #4

Closed hastebrot closed 6 years ago

hastebrot commented 6 years ago

Proposed solution: Add a new option to WorkerOptions that defines a comparator:

interface WorkerOptions {
  comparator: (item: Task, otherItem: Task) => number
}

Augment Task interface with a running index number.

interface Task {
  id: any,
  priority?: number
  action?: TaskAction
}

Allow to sort the tasks with (task, otherTask) => task.priority - otherTask.priority (accending), and (task, otherTask) => otherTask.priority - task.priority (decending).