* @param {boolean} success * @param {number} dir * @private
(success, dir)
| 239 | * @private |
| 240 | */ |
| 241 | complete_(success, dir) { |
| 242 | if (!this.running_) { |
| 243 | return; |
| 244 | } |
| 245 | this.running_ = false; |
| 246 | if (dir != 0) { |
| 247 | // Sort in the completion order. |
| 248 | if (this.segments_.length > 1) { |
| 249 | this.segments_.sort((s1, s2) => { |
| 250 | return s1.delay + s1.duration - (s2.delay + s2.duration); |
| 251 | }); |
| 252 | } |
| 253 | try { |
| 254 | if (dir > 0) { |
| 255 | // Natural order - all set to 1. |
| 256 | for (let i = 0; i < this.segments_.length; i++) { |
| 257 | this.segments_[i].func(1, true); |
| 258 | } |
| 259 | } else { |
| 260 | // Reverse order - all set to 0. |
| 261 | for (let i = this.segments_.length - 1; i >= 0; i--) { |
| 262 | this.segments_[i].func(0, false); |
| 263 | } |
| 264 | } |
| 265 | } catch (e) { |
| 266 | dev().error(TAG_, 'completion failed: ' + e, e); |
| 267 | success = false; |
| 268 | } |
| 269 | } |
| 270 | if (success) { |
| 271 | this.resolve_(); |
| 272 | } else { |
| 273 | this.reject_(); |
| 274 | } |
| 275 | } |
| 276 | |
| 277 | /** |
| 278 | * @param {!{[key: string]: *}} unusedState |
no test coverage detected