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). |
9 * @param steps array of functions to invoke in parallel. | 10 * @param steps array of functions to invoke in parallel. |
| 11 * @param {Object} logger //TODO(JSDOC). |
10 * @param callback callback to invoke on success. | 12 * @param callback callback to invoke on success. |
11 * @param failureCallback callback to invoke on failure. | 13 * @param failureCallback callback to invoke on failure. |
12 */ | 14 */ |
13 function FunctionParallel(name, steps, logger, callback, failureCallback) { | 15 function FunctionParallel(name, steps, logger, callback, failureCallback) { |
14 // Private variables hidden in closure | 16 // Private variables hidden in closure |
15 this.currentStepIdx_ = -1; | 17 this.currentStepIdx_ = -1; |
16 this.failed_ = false; | 18 this.failed_ = false; |
17 this.steps_ = steps; | 19 this.steps_ = steps; |
18 this.callback_ = callback; | 20 this.callback_ = callback; |
19 this.failureCallback_ = failureCallback; | 21 this.failureCallback_ = failureCallback; |
(...skipping 29 matching lines...) Expand all Loading... |
49 */ | 51 */ |
50 FunctionParallel.prototype.nextStep_ = function() { | 52 FunctionParallel.prototype.nextStep_ = function() { |
51 if (--this.remaining == 0 && !this.failed_) { | 53 if (--this.remaining == 0 && !this.failed_) { |
52 this.callback_(); | 54 this.callback_(); |
53 } | 55 } |
54 }; | 56 }; |
55 | 57 |
56 /** | 58 /** |
57 * This function should be called only once on start, so start all the children | 59 * This function should be called only once on start, so start all the children |
58 * at once | 60 * at once |
| 61 * @param {...} var_args //TODO(JSDOC). |
59 */ | 62 */ |
60 FunctionParallel.prototype.start = function(var_args) { | 63 FunctionParallel.prototype.start = function(var_args) { |
61 this.logger.vlog('Starting [' + this.steps_.length + '] parallel tasks with ' | 64 this.logger.vlog('Starting [' + this.steps_.length + '] parallel tasks with ' |
62 + arguments.length + ' argument(s)'); | 65 + arguments.length + ' argument(s)'); |
63 if (this.logger.verbose) { | 66 if (this.logger.verbose) { |
64 for (var j = 0; j < arguments.length; j++) { | 67 for (var j = 0; j < arguments.length; j++) { |
65 this.logger.vlog(arguments[j]); | 68 this.logger.vlog(arguments[j]); |
66 } | 69 } |
67 } | 70 } |
68 for (var i = 0; i < this.steps_.length; i++) { | 71 for (var i = 0; i < this.steps_.length; i++) { |
69 this.logger.vlog('Attempting to start step [' + this.steps_[i].name + ']'); | 72 this.logger.vlog('Attempting to start step [' + this.steps_[i].name + ']'); |
70 try { | 73 try { |
71 this.steps_[i].apply(this, arguments); | 74 this.steps_[i].apply(this, arguments); |
72 } catch (e) { | 75 } catch (e) { |
73 this.onError(e.toString()); | 76 this.onError(e.toString()); |
74 } | 77 } |
75 } | 78 } |
76 }; | 79 }; |
OLD | NEW |