@itwin/core-bentley 3.6.0-dev.8 → 4.0.0-dev.2
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.
- package/CHANGELOG.md +29 -1
- package/LICENSE.md +1 -1
- package/lib/cjs/AccessToken.d.ts +5 -3
- package/lib/cjs/AccessToken.d.ts.map +1 -1
- package/lib/cjs/AccessToken.js.map +1 -1
- package/lib/cjs/BentleyError.d.ts +10 -10
- package/lib/cjs/BentleyError.js +9 -9
- package/lib/cjs/BentleyError.js.map +1 -1
- package/lib/cjs/ByteStream.d.ts +25 -9
- package/lib/cjs/ByteStream.d.ts.map +1 -1
- package/lib/cjs/ByteStream.js +26 -10
- package/lib/cjs/ByteStream.js.map +1 -1
- package/lib/cjs/Id.d.ts +9 -1
- package/lib/cjs/Id.d.ts.map +1 -1
- package/lib/cjs/Id.js +15 -1
- package/lib/cjs/Id.js.map +1 -1
- package/lib/cjs/TypedArrayBuilder.d.ts +64 -6
- package/lib/cjs/TypedArrayBuilder.d.ts.map +1 -1
- package/lib/cjs/TypedArrayBuilder.js +79 -5
- package/lib/cjs/TypedArrayBuilder.js.map +1 -1
- package/lib/cjs/UtilityTypes.d.ts +0 -4
- package/lib/cjs/UtilityTypes.d.ts.map +1 -1
- package/lib/cjs/UtilityTypes.js.map +1 -1
- package/lib/cjs/core-bentley.d.ts +0 -1
- package/lib/cjs/core-bentley.d.ts.map +1 -1
- package/lib/cjs/core-bentley.js +0 -1
- package/lib/cjs/core-bentley.js.map +1 -1
- package/lib/esm/AccessToken.d.ts +5 -3
- package/lib/esm/AccessToken.d.ts.map +1 -1
- package/lib/esm/AccessToken.js.map +1 -1
- package/lib/esm/BentleyError.d.ts +10 -10
- package/lib/esm/BentleyError.js +9 -9
- package/lib/esm/BentleyError.js.map +1 -1
- package/lib/esm/ByteStream.d.ts +25 -9
- package/lib/esm/ByteStream.d.ts.map +1 -1
- package/lib/esm/ByteStream.js +26 -10
- package/lib/esm/ByteStream.js.map +1 -1
- package/lib/esm/Id.d.ts +9 -1
- package/lib/esm/Id.d.ts.map +1 -1
- package/lib/esm/Id.js +15 -1
- package/lib/esm/Id.js.map +1 -1
- package/lib/esm/TypedArrayBuilder.d.ts +64 -6
- package/lib/esm/TypedArrayBuilder.d.ts.map +1 -1
- package/lib/esm/TypedArrayBuilder.js +77 -4
- package/lib/esm/TypedArrayBuilder.js.map +1 -1
- package/lib/esm/UtilityTypes.d.ts +0 -4
- package/lib/esm/UtilityTypes.d.ts.map +1 -1
- package/lib/esm/UtilityTypes.js.map +1 -1
- package/lib/esm/core-bentley.d.ts +0 -1
- package/lib/esm/core-bentley.d.ts.map +1 -1
- package/lib/esm/core-bentley.js +0 -1
- package/lib/esm/core-bentley.js.map +1 -1
- package/package.json +3 -3
- package/lib/cjs/AsyncMutex.d.ts +0 -27
- package/lib/cjs/AsyncMutex.d.ts.map +0 -1
- package/lib/cjs/AsyncMutex.js +0 -44
- package/lib/cjs/AsyncMutex.js.map +0 -1
- package/lib/esm/AsyncMutex.d.ts +0 -27
- package/lib/esm/AsyncMutex.d.ts.map +0 -1
- package/lib/esm/AsyncMutex.js +0 -40
- package/lib/esm/AsyncMutex.js.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"core-bentley.js","sourceRoot":"","sources":["../../src/core-bentley.ts"],"names":[],"mappings":"AAAA;;;+FAG+F;AAC/F,cAAc,eAAe,CAAC;AAC9B,cAAc,UAAU,CAAC;AACzB,cAAc,
|
|
1
|
+
{"version":3,"file":"core-bentley.js","sourceRoot":"","sources":["../../src/core-bentley.ts"],"names":[],"mappings":"AAAA;;;+FAG+F;AAC/F,cAAc,eAAe,CAAC;AAC9B,cAAc,UAAU,CAAC;AACzB,cAAc,WAAW,CAAC;AAC1B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,yBAAyB,CAAC;AACxC,cAAc,kBAAkB,CAAC;AACjC,cAAc,YAAY,CAAC;AAC3B,cAAc,cAAc,CAAC;AAC7B,cAAc,cAAc,CAAC;AAC7B,cAAc,WAAW,CAAC;AAC1B,cAAc,qBAAqB,CAAC;AACpC,cAAc,cAAc,CAAC;AAC7B,cAAc,cAAc,CAAC;AAC7B,cAAc,MAAM,CAAC;AACrB,cAAc,YAAY,CAAC;AAC3B,cAAc,cAAc,CAAC;AAC7B,cAAc,aAAa,CAAC;AAC5B,cAAc,UAAU,CAAC;AACzB,cAAc,UAAU,CAAC;AACzB,cAAc,iBAAiB,CAAC;AAChC,cAAc,oBAAoB,CAAC;AACnC,cAAc,uBAAuB,CAAC;AACtC,cAAc,cAAc,CAAC;AAC7B,cAAc,kBAAkB,CAAC;AACjC,cAAc,iBAAiB,CAAC;AAChC,cAAc,mBAAmB,CAAC;AAClC,cAAc,eAAe,CAAC;AAC9B,cAAc,eAAe,CAAC;AAC9B,cAAc,QAAQ,CAAC;AACvB,cAAc,WAAW,CAAC;AAC1B,cAAc,iBAAiB,CAAC;AAChC,cAAc,qBAAqB,CAAC;AACpC,cAAc,oBAAoB,CAAC;AACnC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,gBAAgB,CAAC;AAE/B;;GAEG;AACH;;;GAGG;AACH;;;GAGG;AACH;;;GAGG;AACH;;;GAGG;AACH;;;GAGG;AACH;;;GAGG;AACH;;;GAGG;AACH;;;GAGG;AACH;;;GAGG","sourcesContent":["/*---------------------------------------------------------------------------------------------\r\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\r\n* See LICENSE.md in the project root for license terms and full copyright notice.\r\n*--------------------------------------------------------------------------------------------*/\r\nexport * from \"./AccessToken\";\r\nexport * from \"./Assert\";\r\nexport * from \"./BeEvent\";\r\nexport * from \"./BentleyError\";\r\nexport * from \"./BentleyLoggerCategory\";\r\nexport * from \"./StatusCategory\";\r\nexport * from \"./BeSQLite\";\r\nexport * from \"./ByteStream\";\r\nexport * from \"./ClassUtils\";\r\nexport * from \"./Compare\";\r\nexport * from \"./CompressedId64Set\";\r\nexport * from \"./Dictionary\";\r\nexport * from \"./Disposable\";\r\nexport * from \"./Id\";\r\nexport * from \"./IndexMap\";\r\nexport * from \"./JsonSchema\";\r\nexport * from \"./JsonUtils\";\r\nexport * from \"./Logger\";\r\nexport * from \"./LRUMap\";\r\nexport * from \"./ObservableSet\";\r\nexport * from \"./OneAtATimeAction\";\r\nexport * from \"./OrderedId64Iterable\";\r\nexport * from \"./OrderedSet\";\r\nexport * from \"./partitionArray\";\r\nexport * from \"./PriorityQueue\";\r\nexport * from \"./ProcessDetector\";\r\nexport * from \"./SortedArray\";\r\nexport * from \"./StringUtils\";\r\nexport * from \"./Time\";\r\nexport * from \"./Tracing\";\r\nexport * from \"./TupleKeyedMap\";\r\nexport * from \"./TypedArrayBuilder\";\r\nexport * from \"./UnexpectedErrors\";\r\nexport * from \"./UtilityTypes\";\r\nexport * from \"./YieldManager\";\r\n\r\n/** @docs-package-description\r\n * The core-bentley package contains classes to solve problems that are common for both client and server use cases.\r\n */\r\n/**\r\n * @docs-group-description BeSQLite\r\n * Classes for working with SQLite databases. SQLite underlies IModelDb and ECDb - see [Executing ECSQL]($docs/learning/ECSQL.md)\r\n */\r\n/**\r\n * @docs-group-description Errors\r\n * Classes for working with errors.\r\n */\r\n/**\r\n * @docs-group-description Events\r\n * Classes for raising and handling events.\r\n */\r\n/**\r\n * @docs-group-description Ids\r\n * Classes for working with unique identifiers.\r\n */\r\n/**\r\n * @docs-group-description Logging\r\n * Classes for configuring and logging diagnostic messages - see [Learning about Logging]($docs/learning/common/Logging.md)\r\n */\r\n/**\r\n * @docs-group-description Collections\r\n * Specialized, customizable collection classes like priority queues.\r\n */\r\n/**\r\n * @docs-group-description Json\r\n * utilities for dealing with Json strings and files.\r\n */\r\n/**\r\n * @docs-group-description Utils\r\n * Miscellaneous utility classes.\r\n */\r\n/**\r\n * @docs-group-description ProcessDetector\r\n * Functions for determining the type of the current JavaScript process.\r\n */\r\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@itwin/core-bentley",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "4.0.0-dev.2",
|
|
4
4
|
"description": "Bentley JavaScript core components",
|
|
5
5
|
"main": "lib/cjs/core-bentley.js",
|
|
6
6
|
"module": "lib/esm/core-bentley.js",
|
|
@@ -21,8 +21,8 @@
|
|
|
21
21
|
"url": "http://www.bentley.com"
|
|
22
22
|
},
|
|
23
23
|
"devDependencies": {
|
|
24
|
-
"@itwin/build-tools": "
|
|
25
|
-
"@itwin/eslint-plugin": "
|
|
24
|
+
"@itwin/build-tools": "4.0.0-dev.2",
|
|
25
|
+
"@itwin/eslint-plugin": "4.0.0-dev.2",
|
|
26
26
|
"@opentelemetry/api": "1.0.4",
|
|
27
27
|
"@types/chai": "4.3.1",
|
|
28
28
|
"@types/chai-as-promised": "^7",
|
package/lib/cjs/AsyncMutex.d.ts
DELETED
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
/** @packageDocumentation
|
|
2
|
-
* @module Utils
|
|
3
|
-
*/
|
|
4
|
-
/**
|
|
5
|
-
* Type of method to unlock the held mutex
|
|
6
|
-
* @see [[AsyncMutex]]
|
|
7
|
-
* @alpha
|
|
8
|
-
*/
|
|
9
|
-
export declare type AsyncMutexUnlockFnType = () => void;
|
|
10
|
-
/**
|
|
11
|
-
* Utility to ensure a block of async code executes atomically.
|
|
12
|
-
* Even if JavaScript precludes the possibility of race conditions between threads, there is potential for
|
|
13
|
-
* race conditions with async code. This utility is needed in cases where a block of async code needs to run
|
|
14
|
-
* to completion before another block is started.
|
|
15
|
-
* This utility was based on this article: https://spin.atomicobject.com/2018/09/10/javascript-concurrency/
|
|
16
|
-
* @alpha
|
|
17
|
-
*/
|
|
18
|
-
export declare class AsyncMutex {
|
|
19
|
-
private _mutex;
|
|
20
|
-
/**
|
|
21
|
-
* Await the return value to setup a lock. The return value
|
|
22
|
-
* is also the unlock function that can be called to unlock
|
|
23
|
-
* the mutex.
|
|
24
|
-
*/
|
|
25
|
-
lock(): Promise<AsyncMutexUnlockFnType>;
|
|
26
|
-
}
|
|
27
|
-
//# sourceMappingURL=AsyncMutex.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"AsyncMutex.d.ts","sourceRoot":"","sources":["../../src/AsyncMutex.ts"],"names":[],"mappings":"AAIA;;GAEG;AAEH;;;;GAIG;AACH,oBAAY,sBAAsB,GAAG,MAAM,IAAI,CAAC;AAEhD;;;;;;;GAOG;AACH,qBAAa,UAAU;IACrB,OAAO,CAAC,MAAM,CAAqB;IAEnC;;;;OAIG;IACU,IAAI,IAAI,OAAO,CAAC,sBAAsB,CAAC;CAgBrD"}
|
package/lib/cjs/AsyncMutex.js
DELETED
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/*---------------------------------------------------------------------------------------------
|
|
3
|
-
* Copyright (c) Bentley Systems, Incorporated. All rights reserved.
|
|
4
|
-
* See LICENSE.md in the project root for license terms and full copyright notice.
|
|
5
|
-
*--------------------------------------------------------------------------------------------*/
|
|
6
|
-
/** @packageDocumentation
|
|
7
|
-
* @module Utils
|
|
8
|
-
*/
|
|
9
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
|
-
exports.AsyncMutex = void 0;
|
|
11
|
-
/**
|
|
12
|
-
* Utility to ensure a block of async code executes atomically.
|
|
13
|
-
* Even if JavaScript precludes the possibility of race conditions between threads, there is potential for
|
|
14
|
-
* race conditions with async code. This utility is needed in cases where a block of async code needs to run
|
|
15
|
-
* to completion before another block is started.
|
|
16
|
-
* This utility was based on this article: https://spin.atomicobject.com/2018/09/10/javascript-concurrency/
|
|
17
|
-
* @alpha
|
|
18
|
-
*/
|
|
19
|
-
class AsyncMutex {
|
|
20
|
-
constructor() {
|
|
21
|
-
this._mutex = Promise.resolve();
|
|
22
|
-
}
|
|
23
|
-
/**
|
|
24
|
-
* Await the return value to setup a lock. The return value
|
|
25
|
-
* is also the unlock function that can be called to unlock
|
|
26
|
-
* the mutex.
|
|
27
|
-
*/
|
|
28
|
-
async lock() {
|
|
29
|
-
/**
|
|
30
|
-
* Note: The promise returned by this method will resolve (with the unlock function, which is actually the
|
|
31
|
-
* mutex’s then’s resolve function) once any previous mutexes have finished and called their
|
|
32
|
-
* respective unlock function that was yielded over their promise.
|
|
33
|
-
*/
|
|
34
|
-
let begin = (_unlock) => { };
|
|
35
|
-
this._mutex = this._mutex.then(async () => {
|
|
36
|
-
return new Promise(begin);
|
|
37
|
-
});
|
|
38
|
-
return new Promise((res) => {
|
|
39
|
-
begin = res;
|
|
40
|
-
});
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
exports.AsyncMutex = AsyncMutex;
|
|
44
|
-
//# sourceMappingURL=AsyncMutex.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"AsyncMutex.js","sourceRoot":"","sources":["../../src/AsyncMutex.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;AAC/F;;GAEG;;;AASH;;;;;;;GAOG;AACH,MAAa,UAAU;IAAvB;QACU,WAAM,GAAG,OAAO,CAAC,OAAO,EAAE,CAAC;IAuBrC,CAAC;IArBC;;;;OAIG;IACI,KAAK,CAAC,IAAI;QACf;;;;WAIG;QACH,IAAI,KAAK,GAA6C,CAAC,OAAO,EAAE,EAAE,GAAG,CAAC,CAAC;QAEvE,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,KAAK,IAAmB,EAAE;YACvD,OAAO,IAAI,OAAO,CAAC,KAAK,CAAC,CAAC;QAC5B,CAAC,CAAC,CAAC;QAEH,OAAO,IAAI,OAAO,CAAC,CAAC,GAAG,EAAE,EAAE;YACzB,KAAK,GAAG,GAAG,CAAC;QACd,CAAC,CAAC,CAAC;IACL,CAAC;CACF;AAxBD,gCAwBC","sourcesContent":["/*---------------------------------------------------------------------------------------------\r\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\r\n* See LICENSE.md in the project root for license terms and full copyright notice.\r\n*--------------------------------------------------------------------------------------------*/\r\n/** @packageDocumentation\r\n * @module Utils\r\n */\r\n\r\n/**\r\n * Type of method to unlock the held mutex\r\n * @see [[AsyncMutex]]\r\n * @alpha\r\n */\r\nexport type AsyncMutexUnlockFnType = () => void;\r\n\r\n/**\r\n * Utility to ensure a block of async code executes atomically.\r\n * Even if JavaScript precludes the possibility of race conditions between threads, there is potential for\r\n * race conditions with async code. This utility is needed in cases where a block of async code needs to run\r\n * to completion before another block is started.\r\n * This utility was based on this article: https://spin.atomicobject.com/2018/09/10/javascript-concurrency/\r\n * @alpha\r\n */\r\nexport class AsyncMutex {\r\n private _mutex = Promise.resolve();\r\n\r\n /**\r\n * Await the return value to setup a lock. The return value\r\n * is also the unlock function that can be called to unlock\r\n * the mutex.\r\n */\r\n public async lock(): Promise<AsyncMutexUnlockFnType> {\r\n /**\r\n * Note: The promise returned by this method will resolve (with the unlock function, which is actually the\r\n * mutex’s then’s resolve function) once any previous mutexes have finished and called their\r\n * respective unlock function that was yielded over their promise.\r\n */\r\n let begin: (unlock: AsyncMutexUnlockFnType) => void = (_unlock) => { };\r\n\r\n this._mutex = this._mutex.then(async (): Promise<void> => {\r\n return new Promise(begin);\r\n });\r\n\r\n return new Promise((res) => {\r\n begin = res;\r\n });\r\n }\r\n}\r\n"]}
|
package/lib/esm/AsyncMutex.d.ts
DELETED
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
/** @packageDocumentation
|
|
2
|
-
* @module Utils
|
|
3
|
-
*/
|
|
4
|
-
/**
|
|
5
|
-
* Type of method to unlock the held mutex
|
|
6
|
-
* @see [[AsyncMutex]]
|
|
7
|
-
* @alpha
|
|
8
|
-
*/
|
|
9
|
-
export declare type AsyncMutexUnlockFnType = () => void;
|
|
10
|
-
/**
|
|
11
|
-
* Utility to ensure a block of async code executes atomically.
|
|
12
|
-
* Even if JavaScript precludes the possibility of race conditions between threads, there is potential for
|
|
13
|
-
* race conditions with async code. This utility is needed in cases where a block of async code needs to run
|
|
14
|
-
* to completion before another block is started.
|
|
15
|
-
* This utility was based on this article: https://spin.atomicobject.com/2018/09/10/javascript-concurrency/
|
|
16
|
-
* @alpha
|
|
17
|
-
*/
|
|
18
|
-
export declare class AsyncMutex {
|
|
19
|
-
private _mutex;
|
|
20
|
-
/**
|
|
21
|
-
* Await the return value to setup a lock. The return value
|
|
22
|
-
* is also the unlock function that can be called to unlock
|
|
23
|
-
* the mutex.
|
|
24
|
-
*/
|
|
25
|
-
lock(): Promise<AsyncMutexUnlockFnType>;
|
|
26
|
-
}
|
|
27
|
-
//# sourceMappingURL=AsyncMutex.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"AsyncMutex.d.ts","sourceRoot":"","sources":["../../src/AsyncMutex.ts"],"names":[],"mappings":"AAIA;;GAEG;AAEH;;;;GAIG;AACH,oBAAY,sBAAsB,GAAG,MAAM,IAAI,CAAC;AAEhD;;;;;;;GAOG;AACH,qBAAa,UAAU;IACrB,OAAO,CAAC,MAAM,CAAqB;IAEnC;;;;OAIG;IACU,IAAI,IAAI,OAAO,CAAC,sBAAsB,CAAC;CAgBrD"}
|
package/lib/esm/AsyncMutex.js
DELETED
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
/*---------------------------------------------------------------------------------------------
|
|
2
|
-
* Copyright (c) Bentley Systems, Incorporated. All rights reserved.
|
|
3
|
-
* See LICENSE.md in the project root for license terms and full copyright notice.
|
|
4
|
-
*--------------------------------------------------------------------------------------------*/
|
|
5
|
-
/** @packageDocumentation
|
|
6
|
-
* @module Utils
|
|
7
|
-
*/
|
|
8
|
-
/**
|
|
9
|
-
* Utility to ensure a block of async code executes atomically.
|
|
10
|
-
* Even if JavaScript precludes the possibility of race conditions between threads, there is potential for
|
|
11
|
-
* race conditions with async code. This utility is needed in cases where a block of async code needs to run
|
|
12
|
-
* to completion before another block is started.
|
|
13
|
-
* This utility was based on this article: https://spin.atomicobject.com/2018/09/10/javascript-concurrency/
|
|
14
|
-
* @alpha
|
|
15
|
-
*/
|
|
16
|
-
export class AsyncMutex {
|
|
17
|
-
constructor() {
|
|
18
|
-
this._mutex = Promise.resolve();
|
|
19
|
-
}
|
|
20
|
-
/**
|
|
21
|
-
* Await the return value to setup a lock. The return value
|
|
22
|
-
* is also the unlock function that can be called to unlock
|
|
23
|
-
* the mutex.
|
|
24
|
-
*/
|
|
25
|
-
async lock() {
|
|
26
|
-
/**
|
|
27
|
-
* Note: The promise returned by this method will resolve (with the unlock function, which is actually the
|
|
28
|
-
* mutex’s then’s resolve function) once any previous mutexes have finished and called their
|
|
29
|
-
* respective unlock function that was yielded over their promise.
|
|
30
|
-
*/
|
|
31
|
-
let begin = (_unlock) => { };
|
|
32
|
-
this._mutex = this._mutex.then(async () => {
|
|
33
|
-
return new Promise(begin);
|
|
34
|
-
});
|
|
35
|
-
return new Promise((res) => {
|
|
36
|
-
begin = res;
|
|
37
|
-
});
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
//# sourceMappingURL=AsyncMutex.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"AsyncMutex.js","sourceRoot":"","sources":["../../src/AsyncMutex.ts"],"names":[],"mappings":"AAAA;;;+FAG+F;AAC/F;;GAEG;AASH;;;;;;;GAOG;AACH,MAAM,OAAO,UAAU;IAAvB;QACU,WAAM,GAAG,OAAO,CAAC,OAAO,EAAE,CAAC;IAuBrC,CAAC;IArBC;;;;OAIG;IACI,KAAK,CAAC,IAAI;QACf;;;;WAIG;QACH,IAAI,KAAK,GAA6C,CAAC,OAAO,EAAE,EAAE,GAAG,CAAC,CAAC;QAEvE,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,KAAK,IAAmB,EAAE;YACvD,OAAO,IAAI,OAAO,CAAC,KAAK,CAAC,CAAC;QAC5B,CAAC,CAAC,CAAC;QAEH,OAAO,IAAI,OAAO,CAAC,CAAC,GAAG,EAAE,EAAE;YACzB,KAAK,GAAG,GAAG,CAAC;QACd,CAAC,CAAC,CAAC;IACL,CAAC;CACF","sourcesContent":["/*---------------------------------------------------------------------------------------------\r\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\r\n* See LICENSE.md in the project root for license terms and full copyright notice.\r\n*--------------------------------------------------------------------------------------------*/\r\n/** @packageDocumentation\r\n * @module Utils\r\n */\r\n\r\n/**\r\n * Type of method to unlock the held mutex\r\n * @see [[AsyncMutex]]\r\n * @alpha\r\n */\r\nexport type AsyncMutexUnlockFnType = () => void;\r\n\r\n/**\r\n * Utility to ensure a block of async code executes atomically.\r\n * Even if JavaScript precludes the possibility of race conditions between threads, there is potential for\r\n * race conditions with async code. This utility is needed in cases where a block of async code needs to run\r\n * to completion before another block is started.\r\n * This utility was based on this article: https://spin.atomicobject.com/2018/09/10/javascript-concurrency/\r\n * @alpha\r\n */\r\nexport class AsyncMutex {\r\n private _mutex = Promise.resolve();\r\n\r\n /**\r\n * Await the return value to setup a lock. The return value\r\n * is also the unlock function that can be called to unlock\r\n * the mutex.\r\n */\r\n public async lock(): Promise<AsyncMutexUnlockFnType> {\r\n /**\r\n * Note: The promise returned by this method will resolve (with the unlock function, which is actually the\r\n * mutex’s then’s resolve function) once any previous mutexes have finished and called their\r\n * respective unlock function that was yielded over their promise.\r\n */\r\n let begin: (unlock: AsyncMutexUnlockFnType) => void = (_unlock) => { };\r\n\r\n this._mutex = this._mutex.then(async (): Promise<void> => {\r\n return new Promise(begin);\r\n });\r\n\r\n return new Promise((res) => {\r\n begin = res;\r\n });\r\n }\r\n}\r\n"]}
|