@creejs/commons-lang 2.1.15 → 2.1.16

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.
@@ -1441,6 +1441,14 @@ var ExecUtils = {
1441
1441
  * }} Deferred
1442
1442
  */
1443
1443
 
1444
+ /**
1445
+ * @typedef {{
1446
+ * promise: Promise<*>,
1447
+ * timerHandler: NodeJS.Timeout,
1448
+ * resolve: (...args:any[])=> void
1449
+ * }} Waiter
1450
+ */
1451
+
1444
1452
  /**
1445
1453
  * @module PromiseUtils
1446
1454
  * @description Promise utility functions for enhanced promise handling, including timeout, delay, parallel execution, and series execution.
@@ -1454,7 +1462,8 @@ var PromiseUtils = {
1454
1462
  series,
1455
1463
  seriesAllSettled,
1456
1464
  parallel,
1457
- parallelAllSettled
1465
+ parallelAllSettled,
1466
+ wait
1458
1467
  };
1459
1468
 
1460
1469
  /**
@@ -1758,6 +1767,38 @@ async function parallelAllSettled (tasks, maxParallel = 5) {
1758
1767
  return rtnVal
1759
1768
  }
1760
1769
 
1770
+ /**
1771
+ * Creates a "Waiter" Object
1772
+ * 1. wait the specified time
1773
+ * 2. can be wakeup immediately by calling resolve
1774
+ * @param {number} waitTime - Timeout duration in milliseconds
1775
+ * @returns {Waiter}
1776
+ */
1777
+ function wait (waitTime) {
1778
+ assertNotNegative(waitTime);
1779
+ /** @type {Waiter} */
1780
+ const rtnVal = {};
1781
+
1782
+ /**
1783
+ * @type {NodeJS.Timeout}
1784
+ */
1785
+ let timerHandler;
1786
+ rtnVal.timerHandler = timerHandler = setTimeout(() => {
1787
+ clearTimeout(timerHandler); // must clear it
1788
+ rtnVal.resolve();
1789
+ }, waitTime);
1790
+
1791
+ rtnVal.promise = new Promise((resolve, reject) => {
1792
+ rtnVal.resolve = (arg) => {
1793
+ if (timerHandler != null) {
1794
+ clearTimeout(timerHandler); // must clear it
1795
+ }
1796
+ resolve(arg);
1797
+ };
1798
+ });
1799
+ return rtnVal
1800
+ }
1801
+
1761
1802
  // owned
1762
1803
 
1763
1804
  // module vars