Skip to content
Yoichiro Tanaka edited this page Dec 28, 2015 · 5 revisions

This Class provides you an ability of a Queue Mechanism. You can register a new task, and the registered tasks will be executed sequentially.

Actually, this is not a completed queue. Because, you must call shiftAndConsumeTask() function to execute a next task like "non-preemptive multitasking".

How to use

Create a new instance of the TaskQueue

var taskQueue = new TaskQueue();

Register a new task

var func = function() {...};
taskQueue.addTask(func);

If the queue size was empty at registering above, the registered task will be called after 10ms.

Execute a next task

You must call shiftAndConsumeTask() function to shift the executed task and to execute the next task.

var func = function() {
  ...
  taskQueue.shiftAndConsumeTask();
};
taskQueue.addTask(func);

Process Flow

chrome.fileSystemProvider.on***Requested.addListener(
  function(options, successCallback, errorCallback) { <- createEventHandler()
    taskQueue.add(function() { <- prepare()
      ...
      taskQueue.shiftAndConsumeTask();
    });
  }
);