@itwin/presentation-common
Version:
Common pieces for iModel.js presentation packages
36 lines • 1.1 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
*/
import { Guid } from "@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
*/
export class AsyncTasksTracker {
_asyncsInProgress = new Set();
get pendingAsyncs() {
return this._asyncsInProgress;
}
trackAsyncTask() {
const id = Guid.createValue();
this._asyncsInProgress.add(id);
return {
[Symbol.dispose]: () => this._asyncsInProgress.delete(id),
};
}
}
//# sourceMappingURL=AsyncTasks.js.map