oolymer / oo-worker

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

(feature) Problem: Tasks are not processed in batches. #2

Closed hastebrot closed 6 years ago

hastebrot commented 6 years ago

We should be able to add runnable tasks, i.e. objects that define a function. These tasks should be processed in batches of n tasks.

Proposed solution: Add basic methods for task handling to oo.Worker: pushTask(), popTask(), peekTask(), numOfTasks.

Add TaskQueue interface which allows to enqueueTasks(tasks). Then you can dequeueTasks(size) and processTasks(tasks) in a batch, which returns a Promise, since the tasks you be asynchronious. Implement TaskQueue in oo.Worker.

interface TaskQueue {
  enqueueTasks(...tasks: Task[]): void
  dequeueTasks(numOfTasks: number): Task[]
  processTasks(...tasks: Task[]): Promise<void>
}

Task itself defines a TaskAction that accepts a TaskActionDone callback for synchronious execution.

interface Task {
  action?: TaskAction
}

type TaskAction = (done?: TaskActionDone) => void
type TaskActionDone = (error?: any) => void