| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 /** | 5 /** |
| 6 * @constructor | 6 * @constructor |
| 7 * @class FunctionSequence to invoke steps in sequence | 7 * @class FunctionSequence to invoke steps in sequence |
| 8 * | 8 * |
| 9 * @param {string} name //TODO(JSDOC). | |
| 10 * @param steps array of functions to invoke in parallel. | 9 * @param steps array of functions to invoke in parallel. |
| 11 * @param {Object} logger //TODO(JSDOC). | |
| 12 * @param callback callback to invoke on success. | 10 * @param callback callback to invoke on success. |
| 13 * @param failureCallback callback to invoke on failure. | 11 * @param failureCallback callback to invoke on failure. |
| 14 */ | 12 */ |
| 15 function FunctionParallel(name, steps, logger, callback, failureCallback) { | 13 function FunctionParallel(name, steps, logger, callback, failureCallback) { |
| 16 // Private variables hidden in closure | 14 // Private variables hidden in closure |
| 17 this.currentStepIdx_ = -1; | 15 this.currentStepIdx_ = -1; |
| 18 this.failed_ = false; | 16 this.failed_ = false; |
| 19 this.steps_ = steps; | 17 this.steps_ = steps; |
| 20 this.callback_ = callback; | 18 this.callback_ = callback; |
| 21 this.failureCallback_ = failureCallback; | 19 this.failureCallback_ = failureCallback; |
| (...skipping 29 matching lines...) Expand all Loading... |
| 51 */ | 49 */ |
| 52 FunctionParallel.prototype.nextStep_ = function() { | 50 FunctionParallel.prototype.nextStep_ = function() { |
| 53 if (--this.remaining == 0 && !this.failed_) { | 51 if (--this.remaining == 0 && !this.failed_) { |
| 54 this.callback_(); | 52 this.callback_(); |
| 55 } | 53 } |
| 56 }; | 54 }; |
| 57 | 55 |
| 58 /** | 56 /** |
| 59 * This function should be called only once on start, so start all the children | 57 * This function should be called only once on start, so start all the children |
| 60 * at once | 58 * at once |
| 61 * @param {...} var_args //TODO(JSDOC). | |
| 62 */ | 59 */ |
| 63 FunctionParallel.prototype.start = function(var_args) { | 60 FunctionParallel.prototype.start = function(var_args) { |
| 64 this.logger.vlog('Starting [' + this.steps_.length + '] parallel tasks with ' | 61 this.logger.vlog('Starting [' + this.steps_.length + '] parallel tasks with ' |
| 65 + arguments.length + ' argument(s)'); | 62 + arguments.length + ' argument(s)'); |
| 66 if (this.logger.verbose) { | 63 if (this.logger.verbose) { |
| 67 for (var j = 0; j < arguments.length; j++) { | 64 for (var j = 0; j < arguments.length; j++) { |
| 68 this.logger.vlog(arguments[j]); | 65 this.logger.vlog(arguments[j]); |
| 69 } | 66 } |
| 70 } | 67 } |
| 71 for (var i = 0; i < this.steps_.length; i++) { | 68 for (var i = 0; i < this.steps_.length; i++) { |
| 72 this.logger.vlog('Attempting to start step [' + this.steps_[i].name + ']'); | 69 this.logger.vlog('Attempting to start step [' + this.steps_[i].name + ']'); |
| 73 try { | 70 try { |
| 74 this.steps_[i].apply(this, arguments); | 71 this.steps_[i].apply(this, arguments); |
| 75 } catch (e) { | 72 } catch (e) { |
| 76 this.onError(e.toString()); | 73 this.onError(e.toString()); |
| 77 } | 74 } |
| 78 } | 75 } |
| 79 }; | 76 }; |
| OLD | NEW |