* @param {boolean | ApplyOptions=} options apply options * @returns {Promise<ModuleId[]>} updated module ids
(options)
| 447 | * @returns {Promise<ModuleId[]>} updated module ids |
| 448 | */ |
| 449 | function internalApply(options) { |
| 450 | options = options || {}; |
| 451 | |
| 452 | applyInvalidatedModules(); |
| 453 | |
| 454 | var results = /** @type {ApplyHandler[]} */ ( |
| 455 | currentUpdateApplyHandlers |
| 456 | ).map(function (handler) { |
| 457 | return handler(/** @type {ApplyOptions} */ (options)); |
| 458 | }); |
| 459 | currentUpdateApplyHandlers = undefined; |
| 460 | |
| 461 | var errors = results |
| 462 | .map(function (r) { |
| 463 | return r.error; |
| 464 | }) |
| 465 | .filter(Boolean); |
| 466 | |
| 467 | if (errors.length > 0) { |
| 468 | return setStatus("abort").then(function () { |
| 469 | throw errors[0]; |
| 470 | }); |
| 471 | } |
| 472 | |
| 473 | // Now in "dispose" phase |
| 474 | var disposePromise = setStatus("dispose"); |
| 475 | |
| 476 | results.forEach(function (result) { |
| 477 | if (result.dispose) result.dispose(); |
| 478 | }); |
| 479 | |
| 480 | // Now in "apply" phase |
| 481 | var applyPromise = setStatus("apply"); |
| 482 | |
| 483 | /** @type {Error | undefined} */ |
| 484 | var error; |
| 485 | /** |
| 486 | * @param {Error} err error thrown while applying |
| 487 | * @returns {void} |
| 488 | */ |
| 489 | var reportError = function (err) { |
| 490 | if (!error) error = err; |
| 491 | }; |
| 492 | |
| 493 | /** @type {ModuleId[]} */ |
| 494 | var outdatedModules = []; |
| 495 | |
| 496 | /** |
| 497 | * @returns {Promise<ModuleId[]>} updated module ids |
| 498 | */ |
| 499 | var onAccepted = function () { |
| 500 | return Promise.all([disposePromise, applyPromise]).then(function () { |
| 501 | // handle errors in accept handlers and self accepted module load |
| 502 | if (error) { |
| 503 | return setStatus("fail").then(function () { |
| 504 | throw error; |
| 505 | }); |
| 506 | } |