@itwin/core-i18n 4.1.0-dev.56 → 4.1.0-dev.62

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.
@@ -22038,28 +22038,36 @@ __webpack_require__.r(__webpack_exports__);
22038
22038
  * Copyright (c) Bentley Systems, Incorporated. All rights reserved.
22039
22039
  * See LICENSE.md in the project root for license terms and full copyright notice.
22040
22040
  *--------------------------------------------------------------------------------------------*/
22041
- /** @internal the default options when constructing yield managers */
22041
+ /** @packageDocumentation
22042
+ * @module Utils
22043
+ */
22042
22044
  const defaultYieldManagerOptions = {
22043
22045
  iterationsBeforeYield: 1000,
22044
22046
  };
22045
- /**
22046
- * @internal
22047
- * An object allowing code to optionally yield with some frequency.
22048
- * useful in some intense loops that make processes unresponsive.
22049
- * primarily a workaround for: https://github.com/nodejs/node-addon-api/issues/1140
22050
- * @note see [[defaultYieldManagerOptions]], the default amount of times it must be called to cause an actual yield is 1000
22047
+ /** Provides a mechanism by which a loop can be made to periodically yield control back to the browser/node environment.
22048
+ * This can alleviate [performance and memory consumption issues](https://github.com/nodejs/node-addon-api/issues/1140).
22049
+ * It maintains a count of the number of iterations that have occurred since the last yield.
22050
+ * The constructor specifies how many iterations of the loop are permitted before yielding.
22051
+ * The loop should `await` [[allowYield]] on each iteration.
22052
+ * [[allowYield]] will yield (and reset the iteration counter) if the counter exceeds the specified maximum.
22053
+ * @public
22051
22054
  */
22052
22055
  class YieldManager {
22056
+ /** Constructor.
22057
+ * @param options Options customizing the yield behavior. Omitted properties are assigned their default values.
22058
+ */
22053
22059
  constructor(options = {}) {
22054
22060
  this._counter = 0;
22055
22061
  this.options = { ...defaultYieldManagerOptions, ...options };
22056
22062
  }
22063
+ /** Increment the iteration counter, yielding control and resetting the counter if [[options.iterationsBeforeYield]] is exceeded. */
22057
22064
  async allowYield() {
22058
22065
  this._counter = (this._counter + 1) % this.options.iterationsBeforeYield;
22059
22066
  if (this._counter === 0) {
22060
22067
  await this.actualYield();
22061
22068
  }
22062
22069
  }
22070
+ /** @internal */
22063
22071
  async actualYield() {
22064
22072
  await new Promise((r) => setTimeout(r, 0));
22065
22073
  }