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