@galacean/engine-core 0.9.19 → 0.9.20

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/main.js CHANGED
@@ -18396,18 +18396,10 @@ var defaultInterval = 500;
18396
18396
  var _config_type;
18397
18397
  config.type = (_config_type = config.type) != null ? _config_type : getMimeTypeFromUrl(url);
18398
18398
  var realRequest = config.type === "image" ? requestImage : requestRes;
18399
- var lastError;
18400
18399
  var executor = new MultiExecutor(function() {
18401
- return realRequest(url, config).onProgress(setProgress).then(function(res) {
18402
- resolve(res);
18403
- executor.stop();
18404
- }).catch(function(err) {
18405
- return lastError = err;
18406
- });
18400
+ return realRequest(url, config).onProgress(setProgress);
18407
18401
  }, retryCount, retryInterval);
18408
- executor.start(function() {
18409
- reject(lastError);
18410
- });
18402
+ executor.start().onError(reject).onComplete(resolve);
18411
18403
  });
18412
18404
  }
18413
18405
  function requestImage(url, config) {
@@ -18494,23 +18486,33 @@ var MultiExecutor = /*#__PURE__*/ function() {
18494
18486
  this.exec = this.exec.bind(this);
18495
18487
  }
18496
18488
  var _proto = MultiExecutor.prototype;
18497
- _proto.start = function start(done) {
18498
- this.done = done;
18489
+ _proto.start = function start() {
18499
18490
  this.exec();
18491
+ return this;
18500
18492
  };
18501
- _proto.stop = function stop() {
18502
- clearTimeout(this._timeoutId);
18493
+ _proto.onComplete = function onComplete(func) {
18494
+ this._onComplete = func;
18495
+ return this;
18496
+ };
18497
+ _proto.onError = function onError(func) {
18498
+ this._onError = func;
18499
+ return this;
18500
+ };
18501
+ _proto.cancel = function cancel() {
18502
+ window.clearTimeout(this._timeoutId);
18503
18503
  };
18504
18504
  _proto.exec = function exec() {
18505
18505
  var _this = this;
18506
18506
  if (this._currentCount >= this.totalCount) {
18507
- this.done && this.done();
18507
+ this._onError && this._onError(this._error);
18508
18508
  return;
18509
18509
  }
18510
18510
  this._currentCount++;
18511
- this.execFunc(this._currentCount).then(function() {
18512
- //@ts-ignore
18513
- _this._timeoutId = setTimeout(_this.exec, _this.interval);
18511
+ this.execFunc(this._currentCount).then(function(result) {
18512
+ return _this._onComplete && _this._onComplete(result);
18513
+ }).catch(function(e) {
18514
+ _this._error = e;
18515
+ _this._timeoutId = window.setTimeout(_this.exec, _this.interval);
18514
18516
  });
18515
18517
  };
18516
18518
  return MultiExecutor;