@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.
@@ -18397,18 +18397,10 @@ var defaultInterval = 500;
18397
18397
  var _config_type;
18398
18398
  config.type = (_config_type = config.type) != null ? _config_type : getMimeTypeFromUrl(url);
18399
18399
  var realRequest = config.type === "image" ? requestImage : requestRes;
18400
- var lastError;
18401
18400
  var executor = new MultiExecutor(function() {
18402
- return realRequest(url, config).onProgress(setProgress).then(function(res) {
18403
- resolve(res);
18404
- executor.stop();
18405
- }).catch(function(err) {
18406
- return lastError = err;
18407
- });
18401
+ return realRequest(url, config).onProgress(setProgress);
18408
18402
  }, retryCount, retryInterval);
18409
- executor.start(function() {
18410
- reject(lastError);
18411
- });
18403
+ executor.start().onError(reject).onComplete(resolve);
18412
18404
  });
18413
18405
  }
18414
18406
  function requestImage(url, config) {
@@ -18495,23 +18487,33 @@ var MultiExecutor = /*#__PURE__*/ function() {
18495
18487
  this.exec = this.exec.bind(this);
18496
18488
  }
18497
18489
  var _proto = MultiExecutor.prototype;
18498
- _proto.start = function start(done) {
18499
- this.done = done;
18490
+ _proto.start = function start() {
18500
18491
  this.exec();
18492
+ return this;
18501
18493
  };
18502
- _proto.stop = function stop() {
18503
- clearTimeout(this._timeoutId);
18494
+ _proto.onComplete = function onComplete(func) {
18495
+ this._onComplete = func;
18496
+ return this;
18497
+ };
18498
+ _proto.onError = function onError(func) {
18499
+ this._onError = func;
18500
+ return this;
18501
+ };
18502
+ _proto.cancel = function cancel() {
18503
+ engineMiniprogramAdapter.window.clearTimeout(this._timeoutId);
18504
18504
  };
18505
18505
  _proto.exec = function exec() {
18506
18506
  var _this = this;
18507
18507
  if (this._currentCount >= this.totalCount) {
18508
- this.done && this.done();
18508
+ this._onError && this._onError(this._error);
18509
18509
  return;
18510
18510
  }
18511
18511
  this._currentCount++;
18512
- this.execFunc(this._currentCount).then(function() {
18513
- //@ts-ignore
18514
- _this._timeoutId = setTimeout(_this.exec, _this.interval);
18512
+ this.execFunc(this._currentCount).then(function(result) {
18513
+ return _this._onComplete && _this._onComplete(result);
18514
+ }).catch(function(e) {
18515
+ _this._error = e;
18516
+ _this._timeoutId = engineMiniprogramAdapter.window.setTimeout(_this.exec, _this.interval);
18515
18517
  });
18516
18518
  };
18517
18519
  return MultiExecutor;
package/dist/module.js CHANGED
@@ -18392,18 +18392,10 @@ var defaultInterval = 500;
18392
18392
  var _config_type;
18393
18393
  config.type = (_config_type = config.type) != null ? _config_type : getMimeTypeFromUrl(url);
18394
18394
  var realRequest = config.type === "image" ? requestImage : requestRes;
18395
- var lastError;
18396
18395
  var executor = new MultiExecutor(function() {
18397
- return realRequest(url, config).onProgress(setProgress).then(function(res) {
18398
- resolve(res);
18399
- executor.stop();
18400
- }).catch(function(err) {
18401
- return lastError = err;
18402
- });
18396
+ return realRequest(url, config).onProgress(setProgress);
18403
18397
  }, retryCount, retryInterval);
18404
- executor.start(function() {
18405
- reject(lastError);
18406
- });
18398
+ executor.start().onError(reject).onComplete(resolve);
18407
18399
  });
18408
18400
  }
18409
18401
  function requestImage(url, config) {
@@ -18490,23 +18482,33 @@ var MultiExecutor = /*#__PURE__*/ function() {
18490
18482
  this.exec = this.exec.bind(this);
18491
18483
  }
18492
18484
  var _proto = MultiExecutor.prototype;
18493
- _proto.start = function start(done) {
18494
- this.done = done;
18485
+ _proto.start = function start() {
18495
18486
  this.exec();
18487
+ return this;
18496
18488
  };
18497
- _proto.stop = function stop() {
18498
- clearTimeout(this._timeoutId);
18489
+ _proto.onComplete = function onComplete(func) {
18490
+ this._onComplete = func;
18491
+ return this;
18492
+ };
18493
+ _proto.onError = function onError(func) {
18494
+ this._onError = func;
18495
+ return this;
18496
+ };
18497
+ _proto.cancel = function cancel() {
18498
+ window.clearTimeout(this._timeoutId);
18499
18499
  };
18500
18500
  _proto.exec = function exec() {
18501
18501
  var _this = this;
18502
18502
  if (this._currentCount >= this.totalCount) {
18503
- this.done && this.done();
18503
+ this._onError && this._onError(this._error);
18504
18504
  return;
18505
18505
  }
18506
18506
  this._currentCount++;
18507
- this.execFunc(this._currentCount).then(function() {
18508
- //@ts-ignore
18509
- _this._timeoutId = setTimeout(_this.exec, _this.interval);
18507
+ this.execFunc(this._currentCount).then(function(result) {
18508
+ return _this._onComplete && _this._onComplete(result);
18509
+ }).catch(function(e) {
18510
+ _this._error = e;
18511
+ _this._timeoutId = window.setTimeout(_this.exec, _this.interval);
18510
18512
  });
18511
18513
  };
18512
18514
  return MultiExecutor;