@itwin/core-bentley 4.0.0-dev.8 → 4.0.0-dev.81
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 +50 -1
- package/lib/cjs/AccessToken.d.ts +10 -10
- package/lib/cjs/AccessToken.d.ts.map +1 -1
- package/lib/cjs/AccessToken.js +9 -9
- package/lib/cjs/AccessToken.js.map +1 -1
- package/lib/cjs/Assert.d.ts +25 -25
- package/lib/cjs/Assert.js +45 -45
- package/lib/cjs/Assert.js.map +1 -1
- package/lib/cjs/BeEvent.d.ts +81 -81
- package/lib/cjs/BeEvent.d.ts.map +1 -1
- package/lib/cjs/BeEvent.js +156 -156
- package/lib/cjs/BeEvent.js.map +1 -1
- package/lib/cjs/BeSQLite.d.ts +172 -170
- package/lib/cjs/BeSQLite.d.ts.map +1 -1
- package/lib/cjs/BeSQLite.js +185 -183
- package/lib/cjs/BeSQLite.js.map +1 -1
- package/lib/cjs/BentleyError.d.ts +378 -378
- package/lib/cjs/BentleyError.d.ts.map +1 -1
- package/lib/cjs/BentleyError.js +703 -702
- package/lib/cjs/BentleyError.js.map +1 -1
- package/lib/cjs/BentleyLoggerCategory.d.ts +11 -11
- package/lib/cjs/BentleyLoggerCategory.js +19 -19
- package/lib/cjs/BentleyLoggerCategory.js.map +1 -1
- package/lib/cjs/ByteStream.d.ts +110 -110
- package/lib/cjs/ByteStream.js +159 -159
- package/lib/cjs/ByteStream.js.map +1 -1
- package/lib/cjs/ClassUtils.d.ts +14 -14
- package/lib/cjs/ClassUtils.js +27 -27
- package/lib/cjs/ClassUtils.js.map +1 -1
- package/lib/cjs/Compare.d.ts +47 -47
- package/lib/cjs/Compare.d.ts.map +1 -1
- package/lib/cjs/Compare.js +75 -75
- package/lib/cjs/Compare.js.map +1 -1
- package/lib/cjs/CompressedId64Set.d.ts +134 -134
- package/lib/cjs/CompressedId64Set.d.ts.map +1 -1
- package/lib/cjs/CompressedId64Set.js +428 -428
- package/lib/cjs/CompressedId64Set.js.map +1 -1
- package/lib/cjs/Dictionary.d.ts +125 -125
- package/lib/cjs/Dictionary.js +203 -203
- package/lib/cjs/Dictionary.js.map +1 -1
- package/lib/cjs/Disposable.d.ts +80 -80
- package/lib/cjs/Disposable.d.ts.map +1 -1
- package/lib/cjs/Disposable.js +120 -120
- package/lib/cjs/Disposable.js.map +1 -1
- package/lib/cjs/Id.d.ts +285 -285
- package/lib/cjs/Id.d.ts.map +1 -1
- package/lib/cjs/Id.js +643 -643
- package/lib/cjs/Id.js.map +1 -1
- package/lib/cjs/IndexMap.d.ts +65 -65
- package/lib/cjs/IndexMap.js +91 -91
- package/lib/cjs/IndexMap.js.map +1 -1
- package/lib/cjs/JsonSchema.d.ts +77 -77
- package/lib/cjs/JsonSchema.d.ts.map +1 -1
- package/lib/cjs/JsonSchema.js +9 -9
- package/lib/cjs/JsonSchema.js.map +1 -1
- package/lib/cjs/JsonUtils.d.ts +78 -78
- package/lib/cjs/JsonUtils.js +151 -151
- package/lib/cjs/JsonUtils.js.map +1 -1
- package/lib/cjs/LRUMap.d.ts +129 -129
- package/lib/cjs/LRUMap.js +333 -333
- package/lib/cjs/LRUMap.js.map +1 -1
- package/lib/cjs/Logger.d.ts +143 -143
- package/lib/cjs/Logger.d.ts.map +1 -1
- package/lib/cjs/Logger.js +256 -258
- package/lib/cjs/Logger.js.map +1 -1
- package/lib/cjs/ObservableSet.d.ts +23 -23
- package/lib/cjs/ObservableSet.js +51 -51
- package/lib/cjs/ObservableSet.js.map +1 -1
- package/lib/cjs/OneAtATimeAction.d.ts +31 -31
- package/lib/cjs/OneAtATimeAction.js +94 -94
- package/lib/cjs/OneAtATimeAction.js.map +1 -1
- package/lib/cjs/OrderedId64Iterable.d.ts +74 -74
- package/lib/cjs/OrderedId64Iterable.d.ts.map +1 -1
- package/lib/cjs/OrderedId64Iterable.js +235 -235
- package/lib/cjs/OrderedId64Iterable.js.map +1 -1
- package/lib/cjs/OrderedSet.d.ts +40 -40
- package/lib/cjs/OrderedSet.js +64 -64
- package/lib/cjs/OrderedSet.js.map +1 -1
- package/lib/cjs/PriorityQueue.d.ts +70 -70
- package/lib/cjs/PriorityQueue.d.ts.map +1 -1
- package/lib/cjs/PriorityQueue.js +140 -140
- package/lib/cjs/PriorityQueue.js.map +1 -1
- package/lib/cjs/ProcessDetector.d.ts +59 -59
- package/lib/cjs/ProcessDetector.js +71 -71
- package/lib/cjs/ProcessDetector.js.map +1 -1
- package/lib/cjs/SortedArray.d.ts +236 -232
- package/lib/cjs/SortedArray.d.ts.map +1 -1
- package/lib/cjs/SortedArray.js +315 -303
- package/lib/cjs/SortedArray.js.map +1 -1
- package/lib/cjs/StatusCategory.d.ts +30 -30
- package/lib/cjs/StatusCategory.d.ts.map +1 -1
- package/lib/cjs/StatusCategory.js +460 -460
- package/lib/cjs/StatusCategory.js.map +1 -1
- package/lib/cjs/StringUtils.d.ts +22 -22
- package/lib/cjs/StringUtils.js +148 -148
- package/lib/cjs/StringUtils.js.map +1 -1
- package/lib/cjs/Time.d.ts +122 -122
- package/lib/cjs/Time.js +152 -152
- package/lib/cjs/Time.js.map +1 -1
- package/lib/cjs/Tracing.d.ts +43 -40
- package/lib/cjs/Tracing.d.ts.map +1 -1
- package/lib/cjs/Tracing.js +134 -130
- package/lib/cjs/Tracing.js.map +1 -1
- package/lib/cjs/TupleKeyedMap.d.ts +36 -36
- package/lib/cjs/TupleKeyedMap.js +102 -102
- package/lib/cjs/TupleKeyedMap.js.map +1 -1
- package/lib/cjs/TypedArrayBuilder.d.ts +155 -155
- package/lib/cjs/TypedArrayBuilder.d.ts.map +1 -1
- package/lib/cjs/TypedArrayBuilder.js +206 -208
- package/lib/cjs/TypedArrayBuilder.js.map +1 -1
- package/lib/cjs/UnexpectedErrors.d.ts +43 -43
- package/lib/cjs/UnexpectedErrors.d.ts.map +1 -1
- package/lib/cjs/UnexpectedErrors.js +68 -68
- package/lib/cjs/UnexpectedErrors.js.map +1 -1
- package/lib/cjs/UtilityTypes.d.ts +112 -96
- package/lib/cjs/UtilityTypes.d.ts.map +1 -1
- package/lib/cjs/UtilityTypes.js +40 -40
- package/lib/cjs/UtilityTypes.js.map +1 -1
- package/lib/cjs/YieldManager.d.ts +18 -18
- package/lib/cjs/YieldManager.js +34 -34
- package/lib/cjs/YieldManager.js.map +1 -1
- package/lib/cjs/core-bentley.d.ts +74 -74
- package/lib/cjs/core-bentley.js +94 -90
- package/lib/cjs/core-bentley.js.map +1 -1
- package/lib/cjs/partitionArray.d.ts +21 -21
- package/lib/cjs/partitionArray.js +43 -43
- package/lib/cjs/partitionArray.js.map +1 -1
- package/lib/esm/AccessToken.d.ts +10 -10
- package/lib/esm/AccessToken.d.ts.map +1 -1
- package/lib/esm/AccessToken.js +8 -8
- package/lib/esm/AccessToken.js.map +1 -1
- package/lib/esm/Assert.d.ts +25 -25
- package/lib/esm/Assert.js +41 -41
- package/lib/esm/Assert.js.map +1 -1
- package/lib/esm/BeEvent.d.ts +81 -81
- package/lib/esm/BeEvent.d.ts.map +1 -1
- package/lib/esm/BeEvent.js +150 -150
- package/lib/esm/BeEvent.js.map +1 -1
- package/lib/esm/BeSQLite.d.ts +172 -170
- package/lib/esm/BeSQLite.d.ts.map +1 -1
- package/lib/esm/BeSQLite.js +182 -180
- package/lib/esm/BeSQLite.js.map +1 -1
- package/lib/esm/BentleyError.d.ts +378 -378
- package/lib/esm/BentleyError.d.ts.map +1 -1
- package/lib/esm/BentleyError.js +699 -698
- package/lib/esm/BentleyError.js.map +1 -1
- package/lib/esm/BentleyLoggerCategory.d.ts +11 -11
- package/lib/esm/BentleyLoggerCategory.js +16 -16
- package/lib/esm/BentleyLoggerCategory.js.map +1 -1
- package/lib/esm/ByteStream.d.ts +110 -110
- package/lib/esm/ByteStream.js +155 -155
- package/lib/esm/ByteStream.js.map +1 -1
- package/lib/esm/ClassUtils.d.ts +14 -14
- package/lib/esm/ClassUtils.js +22 -22
- package/lib/esm/ClassUtils.js.map +1 -1
- package/lib/esm/Compare.d.ts +47 -47
- package/lib/esm/Compare.d.ts.map +1 -1
- package/lib/esm/Compare.js +63 -63
- package/lib/esm/Compare.js.map +1 -1
- package/lib/esm/CompressedId64Set.d.ts +134 -134
- package/lib/esm/CompressedId64Set.d.ts.map +1 -1
- package/lib/esm/CompressedId64Set.js +423 -423
- package/lib/esm/CompressedId64Set.js.map +1 -1
- package/lib/esm/Dictionary.d.ts +125 -125
- package/lib/esm/Dictionary.js +199 -199
- package/lib/esm/Dictionary.js.map +1 -1
- package/lib/esm/Disposable.d.ts +80 -80
- package/lib/esm/Disposable.d.ts.map +1 -1
- package/lib/esm/Disposable.js +112 -112
- package/lib/esm/Disposable.js.map +1 -1
- package/lib/esm/Id.d.ts +285 -285
- package/lib/esm/Id.d.ts.map +1 -1
- package/lib/esm/Id.js +639 -639
- package/lib/esm/Id.js.map +1 -1
- package/lib/esm/IndexMap.d.ts +65 -65
- package/lib/esm/IndexMap.js +86 -86
- package/lib/esm/IndexMap.js.map +1 -1
- package/lib/esm/JsonSchema.d.ts +77 -77
- package/lib/esm/JsonSchema.d.ts.map +1 -1
- package/lib/esm/JsonSchema.js +8 -8
- package/lib/esm/JsonSchema.js.map +1 -1
- package/lib/esm/JsonUtils.d.ts +78 -78
- package/lib/esm/JsonUtils.js +148 -148
- package/lib/esm/JsonUtils.js.map +1 -1
- package/lib/esm/LRUMap.d.ts +129 -129
- package/lib/esm/LRUMap.js +326 -326
- package/lib/esm/LRUMap.js.map +1 -1
- package/lib/esm/Logger.d.ts +143 -143
- package/lib/esm/Logger.d.ts.map +1 -1
- package/lib/esm/Logger.js +253 -253
- package/lib/esm/Logger.js.map +1 -1
- package/lib/esm/ObservableSet.d.ts +23 -23
- package/lib/esm/ObservableSet.js +47 -47
- package/lib/esm/ObservableSet.js.map +1 -1
- package/lib/esm/OneAtATimeAction.d.ts +31 -31
- package/lib/esm/OneAtATimeAction.js +89 -89
- package/lib/esm/OneAtATimeAction.js.map +1 -1
- package/lib/esm/OrderedId64Iterable.d.ts +74 -74
- package/lib/esm/OrderedId64Iterable.d.ts.map +1 -1
- package/lib/esm/OrderedId64Iterable.js +232 -232
- package/lib/esm/OrderedId64Iterable.js.map +1 -1
- package/lib/esm/OrderedSet.d.ts +40 -40
- package/lib/esm/OrderedSet.js +59 -59
- package/lib/esm/OrderedSet.js.map +1 -1
- package/lib/esm/PriorityQueue.d.ts +70 -70
- package/lib/esm/PriorityQueue.d.ts.map +1 -1
- package/lib/esm/PriorityQueue.js +136 -136
- package/lib/esm/PriorityQueue.js.map +1 -1
- package/lib/esm/ProcessDetector.d.ts +59 -59
- package/lib/esm/ProcessDetector.js +67 -67
- package/lib/esm/ProcessDetector.js.map +1 -1
- package/lib/esm/SortedArray.d.ts +236 -232
- package/lib/esm/SortedArray.d.ts.map +1 -1
- package/lib/esm/SortedArray.js +308 -296
- package/lib/esm/SortedArray.js.map +1 -1
- package/lib/esm/StatusCategory.d.ts +30 -30
- package/lib/esm/StatusCategory.d.ts.map +1 -1
- package/lib/esm/StatusCategory.js +455 -454
- package/lib/esm/StatusCategory.js.map +1 -1
- package/lib/esm/StringUtils.d.ts +22 -22
- package/lib/esm/StringUtils.js +142 -142
- package/lib/esm/StringUtils.js.map +1 -1
- package/lib/esm/Time.d.ts +122 -122
- package/lib/esm/Time.js +146 -146
- package/lib/esm/Time.js.map +1 -1
- package/lib/esm/Tracing.d.ts +43 -40
- package/lib/esm/Tracing.d.ts.map +1 -1
- package/lib/esm/Tracing.js +130 -126
- package/lib/esm/Tracing.js.map +1 -1
- package/lib/esm/TupleKeyedMap.d.ts +36 -36
- package/lib/esm/TupleKeyedMap.js +98 -98
- package/lib/esm/TupleKeyedMap.js.map +1 -1
- package/lib/esm/TypedArrayBuilder.d.ts +155 -155
- package/lib/esm/TypedArrayBuilder.d.ts.map +1 -1
- package/lib/esm/TypedArrayBuilder.js +198 -200
- package/lib/esm/TypedArrayBuilder.js.map +1 -1
- package/lib/esm/UnexpectedErrors.d.ts +43 -43
- package/lib/esm/UnexpectedErrors.d.ts.map +1 -1
- package/lib/esm/UnexpectedErrors.js +65 -64
- package/lib/esm/UnexpectedErrors.js.map +1 -1
- package/lib/esm/UtilityTypes.d.ts +112 -96
- package/lib/esm/UtilityTypes.d.ts.map +1 -1
- package/lib/esm/UtilityTypes.js +34 -34
- package/lib/esm/UtilityTypes.js.map +1 -1
- package/lib/esm/YieldManager.d.ts +18 -18
- package/lib/esm/YieldManager.js +30 -30
- package/lib/esm/YieldManager.js.map +1 -1
- package/lib/esm/core-bentley.d.ts +74 -74
- package/lib/esm/core-bentley.js +78 -78
- package/lib/esm/core-bentley.js.map +1 -1
- package/lib/esm/partitionArray.d.ts +21 -21
- package/lib/esm/partitionArray.js +39 -39
- package/lib/esm/partitionArray.js.map +1 -1
- package/package.json +9 -9
package/lib/esm/Disposable.js
CHANGED
|
@@ -1,113 +1,113 @@
|
|
|
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
|
-
* A type guard that checks whether the given argument implements `IDisposable` interface
|
|
10
|
-
* @public
|
|
11
|
-
*/
|
|
12
|
-
export function isIDisposable(obj) {
|
|
13
|
-
// eslint-disable-next-line @typescript-eslint/unbound-method
|
|
14
|
-
return !!obj && (obj instanceof Object) && !!obj.dispose && (typeof obj.dispose === "function");
|
|
15
|
-
}
|
|
16
|
-
/** Convenience function for disposing of a disposable object that may be undefined.
|
|
17
|
-
* This is primarily used to simplify implementations of [[IDisposable.dispose]].
|
|
18
|
-
* As a simple example:
|
|
19
|
-
* ```ts
|
|
20
|
-
* class Disposable implements IDisposable {
|
|
21
|
-
* public member1?: DisposableType1;
|
|
22
|
-
* public member2?: DisposableType2;
|
|
23
|
-
*
|
|
24
|
-
* public dispose() {
|
|
25
|
-
* this.member1 = dispose(this.member1); // If member1 is defined, dispose of it and set it to undefined.
|
|
26
|
-
* this.member2 = dispose(this.member2); // Likewise for member2.
|
|
27
|
-
* }
|
|
28
|
-
* }
|
|
29
|
-
* ```
|
|
30
|
-
* @param disposable The object to be disposed of.
|
|
31
|
-
* @returns undefined
|
|
32
|
-
* @public
|
|
33
|
-
*/
|
|
34
|
-
export function dispose(disposable) {
|
|
35
|
-
if (undefined !== disposable)
|
|
36
|
-
disposable.dispose();
|
|
37
|
-
return undefined;
|
|
38
|
-
}
|
|
39
|
-
/** Disposes of and empties a list of disposable objects.
|
|
40
|
-
* @param list The list of disposable objects.
|
|
41
|
-
* @returns undefined
|
|
42
|
-
* @public
|
|
43
|
-
*/
|
|
44
|
-
export function disposeArray(list) {
|
|
45
|
-
if (undefined === list)
|
|
46
|
-
return undefined;
|
|
47
|
-
for (const entry of list)
|
|
48
|
-
dispose(entry);
|
|
49
|
-
list.length = 0;
|
|
50
|
-
return undefined;
|
|
51
|
-
}
|
|
52
|
-
/** A 'using' function which is a substitution for .NET's using statement. It makes sure that 'dispose'
|
|
53
|
-
* is called on the resource no matter if the func returns or throws. If func returns, the return value
|
|
54
|
-
* of this function is equal to return value of func. If func throws, this function also throws (after
|
|
55
|
-
* disposing the resource).
|
|
56
|
-
* @public
|
|
57
|
-
*/
|
|
58
|
-
export function using(resources, func) {
|
|
59
|
-
if (!Array.isArray(resources))
|
|
60
|
-
return using([resources], func);
|
|
61
|
-
const doDispose = () => resources.forEach((disposable) => disposable.dispose());
|
|
62
|
-
let shouldDisposeImmediately = true;
|
|
63
|
-
try {
|
|
64
|
-
const result = func(...resources);
|
|
65
|
-
if (result instanceof Promise) {
|
|
66
|
-
shouldDisposeImmediately = false;
|
|
67
|
-
result.then(doDispose, doDispose);
|
|
68
|
-
}
|
|
69
|
-
return result;
|
|
70
|
-
}
|
|
71
|
-
finally {
|
|
72
|
-
if (shouldDisposeImmediately)
|
|
73
|
-
doDispose();
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
class FuncDisposable {
|
|
77
|
-
constructor(disposeFunc) { this._disposeFunc = disposeFunc; }
|
|
78
|
-
dispose() { this._disposeFunc(); }
|
|
79
|
-
}
|
|
80
|
-
/** A disposable container of disposable objects.
|
|
81
|
-
* @public
|
|
82
|
-
*/
|
|
83
|
-
export class DisposableList {
|
|
84
|
-
/** Creates a disposable list. */
|
|
85
|
-
constructor(disposables = []) {
|
|
86
|
-
this._disposables = [];
|
|
87
|
-
disposables.forEach((disposable) => {
|
|
88
|
-
this.add(disposable);
|
|
89
|
-
});
|
|
90
|
-
}
|
|
91
|
-
isDisposable(x) {
|
|
92
|
-
return x.dispose !== undefined;
|
|
93
|
-
}
|
|
94
|
-
/** Register an object for disposal. */
|
|
95
|
-
add(disposable) {
|
|
96
|
-
if (this.isDisposable(disposable))
|
|
97
|
-
this._disposables.push(disposable);
|
|
98
|
-
else
|
|
99
|
-
this._disposables.push(new FuncDisposable(disposable));
|
|
100
|
-
}
|
|
101
|
-
/** Unregister disposable object. */
|
|
102
|
-
remove(disposable) {
|
|
103
|
-
const idx = this._disposables.indexOf(disposable);
|
|
104
|
-
if (-1 !== idx)
|
|
105
|
-
this._disposables.splice(idx, 1);
|
|
106
|
-
}
|
|
107
|
-
/** Disposes all registered objects. */
|
|
108
|
-
dispose() {
|
|
109
|
-
for (const disposable of this._disposables)
|
|
110
|
-
disposable.dispose();
|
|
111
|
-
}
|
|
112
|
-
}
|
|
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
|
+
* A type guard that checks whether the given argument implements `IDisposable` interface
|
|
10
|
+
* @public
|
|
11
|
+
*/
|
|
12
|
+
export function isIDisposable(obj) {
|
|
13
|
+
// eslint-disable-next-line @typescript-eslint/unbound-method
|
|
14
|
+
return !!obj && (obj instanceof Object) && !!obj.dispose && (typeof obj.dispose === "function");
|
|
15
|
+
}
|
|
16
|
+
/** Convenience function for disposing of a disposable object that may be undefined.
|
|
17
|
+
* This is primarily used to simplify implementations of [[IDisposable.dispose]].
|
|
18
|
+
* As a simple example:
|
|
19
|
+
* ```ts
|
|
20
|
+
* class Disposable implements IDisposable {
|
|
21
|
+
* public member1?: DisposableType1;
|
|
22
|
+
* public member2?: DisposableType2;
|
|
23
|
+
*
|
|
24
|
+
* public dispose() {
|
|
25
|
+
* this.member1 = dispose(this.member1); // If member1 is defined, dispose of it and set it to undefined.
|
|
26
|
+
* this.member2 = dispose(this.member2); // Likewise for member2.
|
|
27
|
+
* }
|
|
28
|
+
* }
|
|
29
|
+
* ```
|
|
30
|
+
* @param disposable The object to be disposed of.
|
|
31
|
+
* @returns undefined
|
|
32
|
+
* @public
|
|
33
|
+
*/
|
|
34
|
+
export function dispose(disposable) {
|
|
35
|
+
if (undefined !== disposable)
|
|
36
|
+
disposable.dispose();
|
|
37
|
+
return undefined;
|
|
38
|
+
}
|
|
39
|
+
/** Disposes of and empties a list of disposable objects.
|
|
40
|
+
* @param list The list of disposable objects.
|
|
41
|
+
* @returns undefined
|
|
42
|
+
* @public
|
|
43
|
+
*/
|
|
44
|
+
export function disposeArray(list) {
|
|
45
|
+
if (undefined === list)
|
|
46
|
+
return undefined;
|
|
47
|
+
for (const entry of list)
|
|
48
|
+
dispose(entry);
|
|
49
|
+
list.length = 0;
|
|
50
|
+
return undefined;
|
|
51
|
+
}
|
|
52
|
+
/** A 'using' function which is a substitution for .NET's using statement. It makes sure that 'dispose'
|
|
53
|
+
* is called on the resource no matter if the func returns or throws. If func returns, the return value
|
|
54
|
+
* of this function is equal to return value of func. If func throws, this function also throws (after
|
|
55
|
+
* disposing the resource).
|
|
56
|
+
* @public
|
|
57
|
+
*/
|
|
58
|
+
export function using(resources, func) {
|
|
59
|
+
if (!Array.isArray(resources))
|
|
60
|
+
return using([resources], func);
|
|
61
|
+
const doDispose = () => resources.forEach((disposable) => disposable.dispose());
|
|
62
|
+
let shouldDisposeImmediately = true;
|
|
63
|
+
try {
|
|
64
|
+
const result = func(...resources);
|
|
65
|
+
if (result instanceof Promise) {
|
|
66
|
+
shouldDisposeImmediately = false;
|
|
67
|
+
result.then(doDispose, doDispose);
|
|
68
|
+
}
|
|
69
|
+
return result;
|
|
70
|
+
}
|
|
71
|
+
finally {
|
|
72
|
+
if (shouldDisposeImmediately)
|
|
73
|
+
doDispose();
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
class FuncDisposable {
|
|
77
|
+
constructor(disposeFunc) { this._disposeFunc = disposeFunc; }
|
|
78
|
+
dispose() { this._disposeFunc(); }
|
|
79
|
+
}
|
|
80
|
+
/** A disposable container of disposable objects.
|
|
81
|
+
* @public
|
|
82
|
+
*/
|
|
83
|
+
export class DisposableList {
|
|
84
|
+
/** Creates a disposable list. */
|
|
85
|
+
constructor(disposables = []) {
|
|
86
|
+
this._disposables = [];
|
|
87
|
+
disposables.forEach((disposable) => {
|
|
88
|
+
this.add(disposable);
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
isDisposable(x) {
|
|
92
|
+
return x.dispose !== undefined;
|
|
93
|
+
}
|
|
94
|
+
/** Register an object for disposal. */
|
|
95
|
+
add(disposable) {
|
|
96
|
+
if (this.isDisposable(disposable))
|
|
97
|
+
this._disposables.push(disposable);
|
|
98
|
+
else
|
|
99
|
+
this._disposables.push(new FuncDisposable(disposable));
|
|
100
|
+
}
|
|
101
|
+
/** Unregister disposable object. */
|
|
102
|
+
remove(disposable) {
|
|
103
|
+
const idx = this._disposables.indexOf(disposable);
|
|
104
|
+
if (-1 !== idx)
|
|
105
|
+
this._disposables.splice(idx, 1);
|
|
106
|
+
}
|
|
107
|
+
/** Disposes all registered objects. */
|
|
108
|
+
dispose() {
|
|
109
|
+
for (const disposable of this._disposables)
|
|
110
|
+
disposable.dispose();
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
113
|
//# sourceMappingURL=Disposable.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Disposable.js","sourceRoot":"","sources":["../../src/Disposable.ts"],"names":[],"mappings":"AAAA;;;+FAG+F;AAC/F;;GAEG;AAwBH;;;GAGG;AACH,MAAM,UAAU,aAAa,CAAC,GAAY;IACxC,6DAA6D;IAC7D,OAAO,CAAC,CAAC,GAAG,IAAI,CAAC,GAAG,YAAY,MAAM,CAAC,IAAI,CAAC,CAAE,GAAmB,CAAC,OAAO,IAAI,CAAC,OAAQ,GAAmB,CAAC,OAAO,KAAK,UAAU,CAAC,CAAC;AACpI,CAAC;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,MAAM,UAAU,OAAO,CAAC,UAAwB;IAC9C,IAAI,SAAS,KAAK,UAAU;QAC1B,UAAU,CAAC,OAAO,EAAE,CAAC;IACvB,OAAO,SAAS,CAAC;AACnB,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,YAAY,CAAC,IAAoB;IAC/C,IAAI,SAAS,KAAK,IAAI;QACpB,OAAO,SAAS,CAAC;IAEnB,KAAK,MAAM,KAAK,IAAI,IAAI;QACtB,OAAO,CAAC,KAAK,CAAC,CAAC;IAEjB,IAAI,CAAC,MAAM,GAAG,CAAC,CAAC;IAChB,OAAO,SAAS,CAAC;AACnB,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,KAAK,CAAiC,SAAkB,EAAE,IAA4B;IACpG,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,SAAS,CAAC;QAC3B,OAAO,KAAK,CAAC,CAAC,SAAS,CAAC,EAAE,IAAI,CAAC,CAAC;IAElC,MAAM,SAAS,GAAG,GAAG,EAAE,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC,UAAU,EAAE,EAAE,CAA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UAAU,CAAC,CAAC;QAClD,IAAI,CAAC,CAAC,KAAK,GAAG;YACZ,IAAI,CAAC,YAAY,CAAC,MAAM,CAAC,GAAG,EAAE,CAAC,CAAC,CAAC;IACrC,CAAC;IAED,uCAAuC;IAChC,OAAO;QACZ,KAAK,MAAM,UAAU,IAAI,IAAI,CAAC,YAAY;YACxC,UAAU,CAAC,OAAO,EAAE,CAAC;IACzB,CAAC;CACF","sourcesContent":["/*---------------------------------------------------------------------------------------------\
|
|
1
|
+
{"version":3,"file":"Disposable.js","sourceRoot":"","sources":["../../src/Disposable.ts"],"names":[],"mappings":"AAAA;;;+FAG+F;AAC/F;;GAEG;AAwBH;;;GAGG;AACH,MAAM,UAAU,aAAa,CAAC,GAAY;IACxC,6DAA6D;IAC7D,OAAO,CAAC,CAAC,GAAG,IAAI,CAAC,GAAG,YAAY,MAAM,CAAC,IAAI,CAAC,CAAE,GAAmB,CAAC,OAAO,IAAI,CAAC,OAAQ,GAAmB,CAAC,OAAO,KAAK,UAAU,CAAC,CAAC;AACpI,CAAC;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,MAAM,UAAU,OAAO,CAAC,UAAwB;IAC9C,IAAI,SAAS,KAAK,UAAU;QAC1B,UAAU,CAAC,OAAO,EAAE,CAAC;IACvB,OAAO,SAAS,CAAC;AACnB,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,YAAY,CAAC,IAAoB;IAC/C,IAAI,SAAS,KAAK,IAAI;QACpB,OAAO,SAAS,CAAC;IAEnB,KAAK,MAAM,KAAK,IAAI,IAAI;QACtB,OAAO,CAAC,KAAK,CAAC,CAAC;IAEjB,IAAI,CAAC,MAAM,GAAG,CAAC,CAAC;IAChB,OAAO,SAAS,CAAC;AACnB,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,KAAK,CAAiC,SAAkB,EAAE,IAA4B;IACpG,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,SAAS,CAAC;QAC3B,OAAO,KAAK,CAAC,CAAC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CAAC,CAAC,CAAC;IAC3D,CAAC;IAED,oCAAoC;IAC7B,MAAM,CAAC,UAAuB;QACnC,MAAM,GAAG,GAAG,IAAI,CAAC,YAAY,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC;QAClD,IAAI,CAAC,CAAC,KAAK,GAAG;YACZ,IAAI,CAAC,YAAY,CAAC,MAAM,CAAC,GAAG,EAAE,CAAC,CAAC,CAAC;IACrC,CAAC;IAED,uCAAuC;IAChC,OAAO;QACZ,KAAK,MAAM,UAAU,IAAI,IAAI,CAAC,YAAY;YACxC,UAAU,CAAC,OAAO,EAAE,CAAC;IACzB,CAAC;CACF","sourcesContent":["/*---------------------------------------------------------------------------------------------\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\n* See LICENSE.md in the project root for license terms and full copyright notice.\n*--------------------------------------------------------------------------------------------*/\n/** @packageDocumentation\n * @module Utils\n */\n\n/** Interface adopted by a type which has deterministic cleanup logic.\n * For example:\n * - Most rendering-related types, such as [[RenderGraphic]] and [[Viewport]], own WebGL resources which must be explicitly released when no longer needed.\n * - Some low-level objects like [[ECDb]] own native types defined in C++ code which must be explicitly released when no longer needed.\n *\n * A similar concept exists in languages like C++ (implemented as \"destructors\") and C# (\"IDisposable\").\n * However, because TypeScript and Javascript lack any built-in support for deterministic destruction, it is up to the programmer to ensure dispose() is called appropriately.\n * Failure to do so may result in memory leaks or leaking of other resources.\n *\n * IDisposable tends to be contagious; that is, if a type has members which implement IDisposable, that type should also implement IDisposable to dispose of those members.\n *\n * Implementations of IDisposable tend to be more \"low-level\" types. The disposal of such types is often handled on your behalf.\n * However, always consult the documentation for an IDisposable type to determine under what circumstances you are expected to explicitly dispose of it.\n * @public\n */\nexport interface IDisposable {\n /** Disposes of any resources owned by this object.\n * @note The object is generally considered unusable after it has been disposed of.\n */\n dispose(): void;\n}\n\n/**\n * A type guard that checks whether the given argument implements `IDisposable` interface\n * @public\n */\nexport function isIDisposable(obj: unknown): obj is IDisposable {\n // eslint-disable-next-line @typescript-eslint/unbound-method\n return !!obj && (obj instanceof Object) && !!(obj as IDisposable).dispose && (typeof (obj as IDisposable).dispose === \"function\");\n}\n\n/** Convenience function for disposing of a disposable object that may be undefined.\n * This is primarily used to simplify implementations of [[IDisposable.dispose]].\n * As a simple example:\n * ```ts\n * class Disposable implements IDisposable {\n * public member1?: DisposableType1;\n * public member2?: DisposableType2;\n *\n * public dispose() {\n * this.member1 = dispose(this.member1); // If member1 is defined, dispose of it and set it to undefined.\n * this.member2 = dispose(this.member2); // Likewise for member2.\n * }\n * }\n * ```\n * @param disposable The object to be disposed of.\n * @returns undefined\n * @public\n */\nexport function dispose(disposable?: IDisposable): undefined {\n if (undefined !== disposable)\n disposable.dispose();\n return undefined;\n}\n\n/** Disposes of and empties a list of disposable objects.\n * @param list The list of disposable objects.\n * @returns undefined\n * @public\n */\nexport function disposeArray(list?: IDisposable[]): undefined {\n if (undefined === list)\n return undefined;\n\n for (const entry of list)\n dispose(entry);\n\n list.length = 0;\n return undefined;\n}\n\n/** A 'using' function which is a substitution for .NET's using statement. It makes sure that 'dispose'\n * is called on the resource no matter if the func returns or throws. If func returns, the return value\n * of this function is equal to return value of func. If func throws, this function also throws (after\n * disposing the resource).\n * @public\n */\nexport function using<T extends IDisposable, TResult>(resources: T | T[], func: (...r: T[]) => TResult): TResult {\n if (!Array.isArray(resources))\n return using([resources], func);\n\n const doDispose = () => resources.forEach((disposable) => disposable.dispose());\n let shouldDisposeImmediately = true;\n\n try {\n const result = func(...resources);\n if (result instanceof Promise) {\n shouldDisposeImmediately = false;\n result.then(doDispose, doDispose);\n }\n return result;\n } finally {\n if (shouldDisposeImmediately)\n doDispose();\n }\n}\n\n/** A definition of function which may be called to dispose an object\n * @public\n */\nexport type DisposeFunc = () => void;\n\nclass FuncDisposable implements IDisposable {\n private _disposeFunc: () => void;\n constructor(disposeFunc: () => void) { this._disposeFunc = disposeFunc; }\n public dispose() { this._disposeFunc(); }\n}\n\n/** A disposable container of disposable objects.\n * @public\n */\nexport class DisposableList implements IDisposable {\n private _disposables: IDisposable[];\n\n /** Creates a disposable list. */\n constructor(disposables: Array<IDisposable | DisposeFunc> = []) {\n this._disposables = [];\n disposables.forEach((disposable) => {\n this.add(disposable);\n });\n }\n\n private isDisposable(x: IDisposable | DisposeFunc): x is IDisposable {\n return (x as IDisposable).dispose !== undefined;\n }\n\n /** Register an object for disposal. */\n public add(disposable: IDisposable | DisposeFunc) {\n if (this.isDisposable(disposable))\n this._disposables.push(disposable);\n else\n this._disposables.push(new FuncDisposable(disposable));\n }\n\n /** Unregister disposable object. */\n public remove(disposable: IDisposable): void {\n const idx = this._disposables.indexOf(disposable);\n if (-1 !== idx)\n this._disposables.splice(idx, 1);\n }\n\n /** Disposes all registered objects. */\n public dispose(): void {\n for (const disposable of this._disposables)\n disposable.dispose();\n }\n}\n"]}
|