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 steps array of functions to invoke in parallel. | 9 * @param steps array of functions to invoke in parallel. |
10 * @param callback callback to invoke on success. | 10 * @param callback callback to invoke on success. |
(...skipping 13 matching lines...) Expand all Loading... |
24 | 24 |
25 this.nextStep = this.nextStep_.bind(this); | 25 this.nextStep = this.nextStep_.bind(this); |
26 this.onError = this.onError_.bind(this); | 26 this.onError = this.onError_.bind(this); |
27 this.apply = this.start.bind(this); | 27 this.apply = this.start.bind(this); |
28 } | 28 } |
29 | 29 |
30 | 30 |
31 /** | 31 /** |
32 * Error handling function, which fires error callback. | 32 * Error handling function, which fires error callback. |
33 * | 33 * |
| 34 * @private |
34 * @param err error message. | 35 * @param err error message. |
35 */ | 36 */ |
36 FunctionParallel.prototype.onError_ = function(err) { | 37 FunctionParallel.prototype.onError_ = function(err) { |
37 if (!this.failed_) { | 38 if (!this.failed_) { |
38 this.failed_ = true; | 39 this.failed_ = true; |
39 this.failureCallback_(err); | 40 this.failureCallback_(err); |
40 } | 41 } |
41 }; | 42 }; |
42 | 43 |
43 /** | 44 /** |
44 * Advances to next step. This method should not be used externally. In external | 45 * Advances to next step. This method should not be used externally. In external |
45 * cases should be used nextStep function, which is defined in closure and thus | 46 * cases should be used nextStep function, which is defined in closure and thus |
46 * has access to internal variables of functionsequence. | 47 * has access to internal variables of functionsequence. |
| 48 * @private |
47 */ | 49 */ |
48 FunctionParallel.prototype.nextStep_ = function() { | 50 FunctionParallel.prototype.nextStep_ = function() { |
49 if (--this.remaining == 0 && !this.failed_) { | 51 if (--this.remaining == 0 && !this.failed_) { |
50 this.callback_(); | 52 this.callback_(); |
51 } | 53 } |
52 }; | 54 }; |
53 | 55 |
54 /** | 56 /** |
55 * 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 |
56 * at once | 58 * at once |
57 */ | 59 */ |
58 FunctionParallel.prototype.start = function(var_args) { | 60 FunctionParallel.prototype.start = function(var_args) { |
59 this.logger.vlog('Starting [' + this.steps_.length + '] parallel tasks with ' | 61 this.logger.vlog('Starting [' + this.steps_.length + '] parallel tasks with ' |
60 + arguments.length + ' argument(s)'); | 62 + arguments.length + ' argument(s)'); |
61 if (this.logger.verbose) { | 63 if (this.logger.verbose) { |
62 for (var j = 0; j < arguments.length; j++) { | 64 for (var j = 0; j < arguments.length; j++) { |
63 this.logger.vlog(arguments[j]); | 65 this.logger.vlog(arguments[j]); |
64 } | 66 } |
65 } | 67 } |
66 for (var i = 0; i < this.steps_.length; i++) { | 68 for (var i = 0; i < this.steps_.length; i++) { |
67 this.logger.vlog('Attempting to start step [' + this.steps_[i].name + ']'); | 69 this.logger.vlog('Attempting to start step [' + this.steps_[i].name + ']'); |
68 try { | 70 try { |
69 this.steps_[i].apply(this, arguments); | 71 this.steps_[i].apply(this, arguments); |
70 } catch (e) { | 72 } catch (e) { |
71 this.onError(e.toString()); | 73 this.onError(e.toString()); |
72 } | 74 } |
73 } | 75 } |
74 }; | 76 }; |
OLD | NEW |