@itwin/presentation-common
Version:
Common pieces for iModel.js presentation packages
40 lines • 1.28 kB
JavaScript
;
/*---------------------------------------------------------------------------------------------
* Copyright (c) Bentley Systems, Incorporated. All rights reserved.
* See LICENSE.md in the project root for license terms and full copyright notice.
*--------------------------------------------------------------------------------------------*/
/** @packageDocumentation
* @module Core
*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.AsyncTasksTracker = void 0;
const core_bentley_1 = require("@itwin/core-bentley");
/**
* A helper to track ongoing async tasks. Usage:
* ```
* {
* using _r = tracker.trackAsyncTask();
* await doSomethingAsync();
* }
* ```
*
* Can be used with `waitForPendingAsyncs` in test helpers to wait for all
* async tasks to complete.
*
* @internal
*/
class AsyncTasksTracker {
_asyncsInProgress = new Set();
get pendingAsyncs() {
return this._asyncsInProgress;
}
trackAsyncTask() {
const id = core_bentley_1.Guid.createValue();
this._asyncsInProgress.add(id);
return {
[Symbol.dispose]: () => this._asyncsInProgress.delete(id),
};
}
}
exports.AsyncTasksTracker = AsyncTasksTracker;
//# sourceMappingURL=AsyncTasks.js.map