Update To 11.40.268.0
[platform/framework/web/crosswalk.git] / src / ui / file_manager / file_manager / common / js / async_util.js
index f2bf6f8..6204d85 100644 (file)
@@ -2,8 +2,6 @@
 // Use of this source code is governed by a BSD-style license that can be
 // found in the LICENSE file.
 
-'use strict';
-
 /**
  * Namespace for async utility functions.
  */
@@ -17,7 +15,7 @@ var AsyncUtil = {};
  * sequentially done.
  *
  * @param {Array.<T>} array The array to be iterated.
- * @param {function(function(), T, number, Array.<T>} callback The iteration
+ * @param {function(function(), T, number, Array.<T>)} callback The iteration
  *     callback. The first argument is a callback to notify the completion of
  *     the iteration.
  * @param {function()} completionCallback Called when all iterations are
@@ -75,7 +73,7 @@ AsyncUtil.ConcurrentQueue.prototype.getWaitingTasksCount = function() {
 };
 
 /**
- * @return {boolean} Number of running tasks.
+ * @return {number} Number of running tasks.
  */
 AsyncUtil.ConcurrentQueue.prototype.getRunningTasksCount = function() {
   return this.pendingTasks_.length;
@@ -151,6 +149,17 @@ AsyncUtil.ConcurrentQueue.prototype.onTaskFinished_ = function(closure) {
 };
 
 /**
+ * Returns string representation of current AsyncUtil.ConcurrentQueue instance.
+ * @return {string} String representation of the instance.
+ */
+AsyncUtil.ConcurrentQueue.prototype.toString = function() {
+  return 'AsyncUtil.ConcurrentQueue\n' +
+      '- WaitingTasksCount: ' + this.getWaitingTasksCount() + '\n' +
+      '- RunningTasksCount: ' + this.getRunningTasksCount() + '\n' +
+      '- isCancelled: ' + this.isCancelled();
+};
+
+/**
  * Creates a class for executing several asynchronous closures in a fifo queue.
  * Added tasks will be executed sequentially in order they were added.
  *
@@ -166,6 +175,32 @@ AsyncUtil.Queue.prototype = {
 };
 
 /**
+ * A task which is executed by AsyncUtil.Group.
+ *
+ * @param {!function(function())} closure Closure with a completion callback to
+ *     be executed.
+ * @param {!Array.<string>} dependencies Array of dependencies.
+ * @param {!string} name Task identifier. Specify to use in dependencies.
+ *
+ * @constructor
+ */
+AsyncUtil.GroupTask = function(closure, dependencies, name) {
+  this.closure = closure;
+  this.dependencies = dependencies;
+  this.name = name;
+};
+
+/**
+ * Returns string representation of AsyncUti.GroupTask instance.
+ * @return {string} String representation of the instance.
+ */
+AsyncUtil.GroupTask.prototype.toString = function() {
+  return 'AsyncUtil.GroupTask\n' +
+      '- name: ' + this.name + '\n' +
+      '- dependencies: ' + this.dependencies.join();
+};
+
+/**
  * Creates a class for executing several asynchronous closures in a group in
  * a dependency order.
  *
@@ -178,6 +213,15 @@ AsyncUtil.Group = function() {
   this.completionCallbacks_ = [];
 };
 
+AsyncUtil.Group.prototype = {
+  /**
+   * @return {Object.<string, AsyncUtil.GroupTask>} Pending tasks
+   */
+  get pendingTasks() {
+    return this.pendingTasks_;
+  }
+};
+
 /**
  * Enqueues a closure to be executed after dependencies are completed.
  *
@@ -191,11 +235,7 @@ AsyncUtil.Group.prototype.add = function(closure, opt_dependencies, opt_name) {
   var length = Object.keys(this.addedTasks_).length;
   var name = opt_name || ('(unnamed#' + (length + 1) + ')');
 
-  var task = {
-    closure: closure,
-    dependencies: opt_dependencies || [],
-    name: name
-  };
+  var task = new AsyncUtil.GroupTask(closure, opt_dependencies || [], name);
 
   this.addedTasks_[name] = task;
   this.pendingTasks_[name] = task;