a2bei4-utils 1.0.9 → 1.0.10

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.
@@ -1821,6 +1821,10 @@ class IntervalTimer {
1821
1821
  this._fn = fn;
1822
1822
  this._ms = ms;
1823
1823
  this._timerId = null;
1824
+ /**
1825
+ * @type {symbol | null}
1826
+ */
1827
+ this._loopId = null;
1824
1828
  }
1825
1829
 
1826
1830
  /**
@@ -1829,8 +1833,17 @@ class IntervalTimer {
1829
1833
  */
1830
1834
  start() {
1831
1835
  this.stop();
1836
+
1837
+ const curLoopId = Symbol();
1838
+ this._loopId = curLoopId;
1839
+
1832
1840
  const loop = () => {
1841
+ if (this._loopId !== curLoopId) return;
1842
+
1833
1843
  this._fn(); // 执行业务
1844
+
1845
+ if (this._loopId !== curLoopId) return;
1846
+
1834
1847
  this._timerId = setTimeout(loop, this._ms);
1835
1848
  };
1836
1849
  loop(); // 立即执行第一次
@@ -1840,6 +1853,7 @@ class IntervalTimer {
1840
1853
  * 停止定时器。
1841
1854
  */
1842
1855
  stop() {
1856
+ this._loopId = null;
1843
1857
  if (this._timerId !== null) {
1844
1858
  clearTimeout(this._timerId);
1845
1859
  this._timerId = null;