@itwin/core-bentley 4.0.0-dev.7 → 4.0.0-dev.72
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/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/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/ByteStream.d.ts +110 -110
- package/lib/cjs/ByteStream.js +159 -159
- package/lib/cjs/ClassUtils.d.ts +14 -14
- package/lib/cjs/ClassUtils.js +27 -27
- 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/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/Disposable.d.ts +80 -80
- package/lib/cjs/Disposable.d.ts.map +1 -1
- package/lib/cjs/Disposable.js +120 -120
- 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/IndexMap.d.ts +65 -65
- package/lib/cjs/IndexMap.js +91 -91
- 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/JsonUtils.d.ts +78 -78
- package/lib/cjs/JsonUtils.js +151 -151
- 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/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/OrderedSet.d.ts +40 -40
- package/lib/cjs/OrderedSet.js +64 -64
- 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/ProcessDetector.d.ts +59 -59
- package/lib/cjs/ProcessDetector.js +71 -71
- 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/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/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/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/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/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/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/ByteStream.d.ts +110 -110
- package/lib/esm/ByteStream.js +155 -155
- package/lib/esm/ClassUtils.d.ts +14 -14
- package/lib/esm/ClassUtils.js +22 -22
- 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/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/Disposable.d.ts +80 -80
- package/lib/esm/Disposable.d.ts.map +1 -1
- package/lib/esm/Disposable.js +112 -112
- 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/IndexMap.d.ts +65 -65
- package/lib/esm/IndexMap.js +86 -86
- 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/JsonUtils.d.ts +78 -78
- package/lib/esm/JsonUtils.js +148 -148
- 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/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/OrderedSet.d.ts +40 -40
- package/lib/esm/OrderedSet.js +59 -59
- 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/ProcessDetector.d.ts +59 -59
- package/lib/esm/ProcessDetector.js +67 -67
- 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/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/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/core-bentley.d.ts +74 -74
- package/lib/esm/core-bentley.js +78 -78
- package/lib/esm/partitionArray.d.ts +21 -21
- package/lib/esm/partitionArray.js +39 -39
- package/package.json +9 -9
package/lib/cjs/Time.d.ts
CHANGED
|
@@ -1,123 +1,123 @@
|
|
|
1
|
-
/** @packageDocumentation
|
|
2
|
-
* @module Utils
|
|
3
|
-
*/
|
|
4
|
-
/** A duration of time. Can be either positive (towards future) or negative (in the past).
|
|
5
|
-
* BeDurations are immutable.
|
|
6
|
-
* @public
|
|
7
|
-
*/
|
|
8
|
-
export declare class BeDuration {
|
|
9
|
-
private readonly _milliseconds;
|
|
10
|
-
private constructor();
|
|
11
|
-
/** The duration in milliseconds */
|
|
12
|
-
get milliseconds(): number;
|
|
13
|
-
get seconds(): number;
|
|
14
|
-
/** Create a BeDuration from seconds.
|
|
15
|
-
* @param seconds the number of seconds for this BeDuration
|
|
16
|
-
*/
|
|
17
|
-
static fromSeconds(seconds: number): BeDuration;
|
|
18
|
-
/** Create a BeDuration from milliseconds.
|
|
19
|
-
* @param milliseconds the number of milliseconds for this BeDuration
|
|
20
|
-
*/
|
|
21
|
-
static fromMilliseconds(milliseconds: number): BeDuration;
|
|
22
|
-
/** Determine whether this BeDuration is 0 seconds */
|
|
23
|
-
get isZero(): boolean;
|
|
24
|
-
/** Determine whether this BeDuration is towards the future */
|
|
25
|
-
get isTowardsFuture(): boolean;
|
|
26
|
-
/** Determine whether this BeDuration is towards the past */
|
|
27
|
-
get isTowardsPast(): boolean;
|
|
28
|
-
/** Subtract a BeDuration from this BeDuration, returning a new BeDuration. */
|
|
29
|
-
minus(other: BeDuration): BeDuration;
|
|
30
|
-
/** Add a BeDuration to this BeDuration, returning a new BeDuration */
|
|
31
|
-
plus(other: BeDuration): BeDuration;
|
|
32
|
-
/** Utility function to just wait for the specified time
|
|
33
|
-
* @param ms Duration in milliseconds to wait
|
|
34
|
-
* @return Promise that resolves after the specified wait period
|
|
35
|
-
*/
|
|
36
|
-
static wait(ms: number): Promise<void>;
|
|
37
|
-
/** Utility function to wait for either the specified time or a promise, whichever resolves first
|
|
38
|
-
* @param ms Maximum duration in milliseconds to wait
|
|
39
|
-
* @param promise A pending promise to wait for
|
|
40
|
-
* @return Promise that resolves after the specified wait period or the provided promise resolves, whichever comes first
|
|
41
|
-
*/
|
|
42
|
-
static race<T>(ms: number, promise: PromiseLike<T>): Promise<T | void>;
|
|
43
|
-
/** Utility function to just wait for the specified time
|
|
44
|
-
* @return Promise that resolves after the specified wait period
|
|
45
|
-
*/
|
|
46
|
-
wait(): Promise<void>;
|
|
47
|
-
/** Execute a function after delaying by this duration.
|
|
48
|
-
* @param fn the function to execute after the delay
|
|
49
|
-
* @param scope An optional object scope to serve as the 'this' pointer when `fn` is invoked.
|
|
50
|
-
* @param args optional arguments to `fn`
|
|
51
|
-
* @return Promise resolved by `fn`
|
|
52
|
-
*/
|
|
53
|
-
executeAfter<T>(fn: (...args: any[]) => T, scope?: any, ...args: any[]): Promise<T>;
|
|
54
|
-
}
|
|
55
|
-
/** A specific point in time relative to the current time.
|
|
56
|
-
* BeTimePoints are used for timing operations. They are created from a BeDuration relative to the "now".
|
|
57
|
-
* BeTimePoints are immutable.
|
|
58
|
-
* @public
|
|
59
|
-
*/
|
|
60
|
-
export declare class BeTimePoint {
|
|
61
|
-
private readonly _milliseconds;
|
|
62
|
-
/** the time in milliseconds, of this BeTimePoint (relative to January 1, 1970 00:00:00 UTC.) */
|
|
63
|
-
get milliseconds(): number;
|
|
64
|
-
private constructor();
|
|
65
|
-
/** Create a BeTimePoint from Date.now() */
|
|
66
|
-
static now(): BeTimePoint;
|
|
67
|
-
/** Create a BeTimePoint at a specified duration in the future from now
|
|
68
|
-
* @param val the duration from now
|
|
69
|
-
*/
|
|
70
|
-
static fromNow(val: BeDuration): BeTimePoint;
|
|
71
|
-
/** Create a BeTimePoint at a specified duration in the past before now
|
|
72
|
-
* @param val the duration before now
|
|
73
|
-
*/
|
|
74
|
-
static beforeNow(val: BeDuration): BeTimePoint;
|
|
75
|
-
/** Determine whether this BeTimePoint is a time in the future from the time this method is called (it calls now()!) */
|
|
76
|
-
get isInFuture(): boolean;
|
|
77
|
-
/** Determine whether this BeTimePoint is a time that has already passed before the time this method is called (it calls now()!) */
|
|
78
|
-
get isInPast(): boolean;
|
|
79
|
-
/** Determine whether this BeTimePoint happens before another one.
|
|
80
|
-
* @param other the other BeTimePoint.
|
|
81
|
-
*/
|
|
82
|
-
before(other: BeTimePoint): boolean;
|
|
83
|
-
/** Determine whether this BeTimePoint happens after another one.
|
|
84
|
-
* @param other the other BeTimePoint.
|
|
85
|
-
*/
|
|
86
|
-
after(other: BeTimePoint): boolean;
|
|
87
|
-
/** Subtract a BeDuration from this BeTimePoint, returning a new BeTimePoint. This moves this BeTimePoint backwards in time if BeDuration.isTowardsFuture() === true
|
|
88
|
-
* @param duration the duration to subtract.
|
|
89
|
-
*/
|
|
90
|
-
minus(duration: BeDuration): BeTimePoint;
|
|
91
|
-
/** Subtract a BeDuration from this BeTimePoint, returning a new BeTimePoint. This moves this BeTimePoint backwards in time if BeDuration.isTowardsFuture() === true
|
|
92
|
-
* @param duration the duration to subtract.
|
|
93
|
-
*/
|
|
94
|
-
plus(duration: BeDuration): BeTimePoint;
|
|
95
|
-
}
|
|
96
|
-
/** A StopWatch for timing operations.
|
|
97
|
-
* @public
|
|
98
|
-
*/
|
|
99
|
-
export declare class StopWatch {
|
|
100
|
-
description?: string | undefined;
|
|
101
|
-
private _start?;
|
|
102
|
-
private _stop?;
|
|
103
|
-
/** Get the elapsed time since start() on a running timer. */
|
|
104
|
-
get current(): BeDuration;
|
|
105
|
-
/** Get the elapsed time, in seconds, since start() on a running timer. */
|
|
106
|
-
get currentSeconds(): number;
|
|
107
|
-
/** Get the elapsed time between start() and stop() on this timer in milliseconds. */
|
|
108
|
-
get elapsed(): BeDuration;
|
|
109
|
-
/** Get the elapsed time, in seconds, between start() and stop() on this timer. */
|
|
110
|
-
get elapsedSeconds(): number;
|
|
111
|
-
/** ctor for StopWatch
|
|
112
|
-
* @param description optional string stored with the StopWatch
|
|
113
|
-
* @param startImmediately if true, StopWatch is started when created. Otherwise, call start() explicitly.
|
|
114
|
-
*/
|
|
115
|
-
constructor(description?: string | undefined, startImmediately?: boolean);
|
|
116
|
-
/** Start the stopwatch. Any future time measurements will be based on this new value. */
|
|
117
|
-
start(): void;
|
|
118
|
-
/** Stop the stopwatch so that the duration can be viewed later. */
|
|
119
|
-
stop(): BeDuration;
|
|
120
|
-
/** Clear the StopWatch */
|
|
121
|
-
reset(): void;
|
|
122
|
-
}
|
|
1
|
+
/** @packageDocumentation
|
|
2
|
+
* @module Utils
|
|
3
|
+
*/
|
|
4
|
+
/** A duration of time. Can be either positive (towards future) or negative (in the past).
|
|
5
|
+
* BeDurations are immutable.
|
|
6
|
+
* @public
|
|
7
|
+
*/
|
|
8
|
+
export declare class BeDuration {
|
|
9
|
+
private readonly _milliseconds;
|
|
10
|
+
private constructor();
|
|
11
|
+
/** The duration in milliseconds */
|
|
12
|
+
get milliseconds(): number;
|
|
13
|
+
get seconds(): number;
|
|
14
|
+
/** Create a BeDuration from seconds.
|
|
15
|
+
* @param seconds the number of seconds for this BeDuration
|
|
16
|
+
*/
|
|
17
|
+
static fromSeconds(seconds: number): BeDuration;
|
|
18
|
+
/** Create a BeDuration from milliseconds.
|
|
19
|
+
* @param milliseconds the number of milliseconds for this BeDuration
|
|
20
|
+
*/
|
|
21
|
+
static fromMilliseconds(milliseconds: number): BeDuration;
|
|
22
|
+
/** Determine whether this BeDuration is 0 seconds */
|
|
23
|
+
get isZero(): boolean;
|
|
24
|
+
/** Determine whether this BeDuration is towards the future */
|
|
25
|
+
get isTowardsFuture(): boolean;
|
|
26
|
+
/** Determine whether this BeDuration is towards the past */
|
|
27
|
+
get isTowardsPast(): boolean;
|
|
28
|
+
/** Subtract a BeDuration from this BeDuration, returning a new BeDuration. */
|
|
29
|
+
minus(other: BeDuration): BeDuration;
|
|
30
|
+
/** Add a BeDuration to this BeDuration, returning a new BeDuration */
|
|
31
|
+
plus(other: BeDuration): BeDuration;
|
|
32
|
+
/** Utility function to just wait for the specified time
|
|
33
|
+
* @param ms Duration in milliseconds to wait
|
|
34
|
+
* @return Promise that resolves after the specified wait period
|
|
35
|
+
*/
|
|
36
|
+
static wait(ms: number): Promise<void>;
|
|
37
|
+
/** Utility function to wait for either the specified time or a promise, whichever resolves first
|
|
38
|
+
* @param ms Maximum duration in milliseconds to wait
|
|
39
|
+
* @param promise A pending promise to wait for
|
|
40
|
+
* @return Promise that resolves after the specified wait period or the provided promise resolves, whichever comes first
|
|
41
|
+
*/
|
|
42
|
+
static race<T>(ms: number, promise: PromiseLike<T>): Promise<T | void>;
|
|
43
|
+
/** Utility function to just wait for the specified time
|
|
44
|
+
* @return Promise that resolves after the specified wait period
|
|
45
|
+
*/
|
|
46
|
+
wait(): Promise<void>;
|
|
47
|
+
/** Execute a function after delaying by this duration.
|
|
48
|
+
* @param fn the function to execute after the delay
|
|
49
|
+
* @param scope An optional object scope to serve as the 'this' pointer when `fn` is invoked.
|
|
50
|
+
* @param args optional arguments to `fn`
|
|
51
|
+
* @return Promise resolved by `fn`
|
|
52
|
+
*/
|
|
53
|
+
executeAfter<T>(fn: (...args: any[]) => T, scope?: any, ...args: any[]): Promise<T>;
|
|
54
|
+
}
|
|
55
|
+
/** A specific point in time relative to the current time.
|
|
56
|
+
* BeTimePoints are used for timing operations. They are created from a BeDuration relative to the "now".
|
|
57
|
+
* BeTimePoints are immutable.
|
|
58
|
+
* @public
|
|
59
|
+
*/
|
|
60
|
+
export declare class BeTimePoint {
|
|
61
|
+
private readonly _milliseconds;
|
|
62
|
+
/** the time in milliseconds, of this BeTimePoint (relative to January 1, 1970 00:00:00 UTC.) */
|
|
63
|
+
get milliseconds(): number;
|
|
64
|
+
private constructor();
|
|
65
|
+
/** Create a BeTimePoint from Date.now() */
|
|
66
|
+
static now(): BeTimePoint;
|
|
67
|
+
/** Create a BeTimePoint at a specified duration in the future from now
|
|
68
|
+
* @param val the duration from now
|
|
69
|
+
*/
|
|
70
|
+
static fromNow(val: BeDuration): BeTimePoint;
|
|
71
|
+
/** Create a BeTimePoint at a specified duration in the past before now
|
|
72
|
+
* @param val the duration before now
|
|
73
|
+
*/
|
|
74
|
+
static beforeNow(val: BeDuration): BeTimePoint;
|
|
75
|
+
/** Determine whether this BeTimePoint is a time in the future from the time this method is called (it calls now()!) */
|
|
76
|
+
get isInFuture(): boolean;
|
|
77
|
+
/** Determine whether this BeTimePoint is a time that has already passed before the time this method is called (it calls now()!) */
|
|
78
|
+
get isInPast(): boolean;
|
|
79
|
+
/** Determine whether this BeTimePoint happens before another one.
|
|
80
|
+
* @param other the other BeTimePoint.
|
|
81
|
+
*/
|
|
82
|
+
before(other: BeTimePoint): boolean;
|
|
83
|
+
/** Determine whether this BeTimePoint happens after another one.
|
|
84
|
+
* @param other the other BeTimePoint.
|
|
85
|
+
*/
|
|
86
|
+
after(other: BeTimePoint): boolean;
|
|
87
|
+
/** Subtract a BeDuration from this BeTimePoint, returning a new BeTimePoint. This moves this BeTimePoint backwards in time if BeDuration.isTowardsFuture() === true
|
|
88
|
+
* @param duration the duration to subtract.
|
|
89
|
+
*/
|
|
90
|
+
minus(duration: BeDuration): BeTimePoint;
|
|
91
|
+
/** Subtract a BeDuration from this BeTimePoint, returning a new BeTimePoint. This moves this BeTimePoint backwards in time if BeDuration.isTowardsFuture() === true
|
|
92
|
+
* @param duration the duration to subtract.
|
|
93
|
+
*/
|
|
94
|
+
plus(duration: BeDuration): BeTimePoint;
|
|
95
|
+
}
|
|
96
|
+
/** A StopWatch for timing operations.
|
|
97
|
+
* @public
|
|
98
|
+
*/
|
|
99
|
+
export declare class StopWatch {
|
|
100
|
+
description?: string | undefined;
|
|
101
|
+
private _start?;
|
|
102
|
+
private _stop?;
|
|
103
|
+
/** Get the elapsed time since start() on a running timer. */
|
|
104
|
+
get current(): BeDuration;
|
|
105
|
+
/** Get the elapsed time, in seconds, since start() on a running timer. */
|
|
106
|
+
get currentSeconds(): number;
|
|
107
|
+
/** Get the elapsed time between start() and stop() on this timer in milliseconds. */
|
|
108
|
+
get elapsed(): BeDuration;
|
|
109
|
+
/** Get the elapsed time, in seconds, between start() and stop() on this timer. */
|
|
110
|
+
get elapsedSeconds(): number;
|
|
111
|
+
/** ctor for StopWatch
|
|
112
|
+
* @param description optional string stored with the StopWatch
|
|
113
|
+
* @param startImmediately if true, StopWatch is started when created. Otherwise, call start() explicitly.
|
|
114
|
+
*/
|
|
115
|
+
constructor(description?: string | undefined, startImmediately?: boolean);
|
|
116
|
+
/** Start the stopwatch. Any future time measurements will be based on this new value. */
|
|
117
|
+
start(): void;
|
|
118
|
+
/** Stop the stopwatch so that the duration can be viewed later. */
|
|
119
|
+
stop(): BeDuration;
|
|
120
|
+
/** Clear the StopWatch */
|
|
121
|
+
reset(): void;
|
|
122
|
+
}
|
|
123
123
|
//# sourceMappingURL=Time.d.ts.map
|
package/lib/cjs/Time.js
CHANGED
|
@@ -1,153 +1,153 @@
|
|
|
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.StopWatch = exports.BeTimePoint = exports.BeDuration = void 0;
|
|
11
|
-
/** A duration of time. Can be either positive (towards future) or negative (in the past).
|
|
12
|
-
* BeDurations are immutable.
|
|
13
|
-
* @public
|
|
14
|
-
*/
|
|
15
|
-
class BeDuration {
|
|
16
|
-
constructor(milliseconds = 0) { this._milliseconds = milliseconds; }
|
|
17
|
-
/** The duration in milliseconds */
|
|
18
|
-
get milliseconds() { return this._milliseconds; }
|
|
19
|
-
get seconds() { return this._milliseconds / 1000; }
|
|
20
|
-
/** Create a BeDuration from seconds.
|
|
21
|
-
* @param seconds the number of seconds for this BeDuration
|
|
22
|
-
*/
|
|
23
|
-
static fromSeconds(seconds) { return new BeDuration(seconds * 1000); }
|
|
24
|
-
/** Create a BeDuration from milliseconds.
|
|
25
|
-
* @param milliseconds the number of milliseconds for this BeDuration
|
|
26
|
-
*/
|
|
27
|
-
static fromMilliseconds(milliseconds) { return new BeDuration(milliseconds); }
|
|
28
|
-
/** Determine whether this BeDuration is 0 seconds */
|
|
29
|
-
get isZero() { return this._milliseconds === 0; }
|
|
30
|
-
/** Determine whether this BeDuration is towards the future */
|
|
31
|
-
get isTowardsFuture() { return this._milliseconds > 0; }
|
|
32
|
-
/** Determine whether this BeDuration is towards the past */
|
|
33
|
-
get isTowardsPast() { return this._milliseconds < 0; }
|
|
34
|
-
/** Subtract a BeDuration from this BeDuration, returning a new BeDuration. */
|
|
35
|
-
minus(other) { return new BeDuration(this._milliseconds - other._milliseconds); }
|
|
36
|
-
/** Add a BeDuration to this BeDuration, returning a new BeDuration */
|
|
37
|
-
plus(other) { return new BeDuration(this._milliseconds + other._milliseconds); }
|
|
38
|
-
/** Utility function to just wait for the specified time
|
|
39
|
-
* @param ms Duration in milliseconds to wait
|
|
40
|
-
* @return Promise that resolves after the specified wait period
|
|
41
|
-
*/
|
|
42
|
-
static async wait(ms) {
|
|
43
|
-
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
44
|
-
}
|
|
45
|
-
/** Utility function to wait for either the specified time or a promise, whichever resolves first
|
|
46
|
-
* @param ms Maximum duration in milliseconds to wait
|
|
47
|
-
* @param promise A pending promise to wait for
|
|
48
|
-
* @return Promise that resolves after the specified wait period or the provided promise resolves, whichever comes first
|
|
49
|
-
*/
|
|
50
|
-
static async race(ms, promise) {
|
|
51
|
-
let timeout;
|
|
52
|
-
const waitPromise = new Promise((resolve) => {
|
|
53
|
-
timeout = setTimeout(resolve, ms);
|
|
54
|
-
});
|
|
55
|
-
return Promise.race([waitPromise, promise]).finally(() => {
|
|
56
|
-
if (timeout)
|
|
57
|
-
clearTimeout(timeout);
|
|
58
|
-
});
|
|
59
|
-
}
|
|
60
|
-
/** Utility function to just wait for the specified time
|
|
61
|
-
* @return Promise that resolves after the specified wait period
|
|
62
|
-
*/
|
|
63
|
-
async wait() {
|
|
64
|
-
return new Promise((resolve) => setTimeout(resolve, this._milliseconds));
|
|
65
|
-
}
|
|
66
|
-
/** Execute a function after delaying by this duration.
|
|
67
|
-
* @param fn the function to execute after the delay
|
|
68
|
-
* @param scope An optional object scope to serve as the 'this' pointer when `fn` is invoked.
|
|
69
|
-
* @param args optional arguments to `fn`
|
|
70
|
-
* @return Promise resolved by `fn`
|
|
71
|
-
*/
|
|
72
|
-
async executeAfter(fn, scope, ...args) {
|
|
73
|
-
return new Promise((resolve) => setTimeout(() => resolve(fn.apply(scope, args)), this._milliseconds));
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
exports.BeDuration = BeDuration;
|
|
77
|
-
/** A specific point in time relative to the current time.
|
|
78
|
-
* BeTimePoints are used for timing operations. They are created from a BeDuration relative to the "now".
|
|
79
|
-
* BeTimePoints are immutable.
|
|
80
|
-
* @public
|
|
81
|
-
*/
|
|
82
|
-
class BeTimePoint {
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
/** Create a BeTimePoint from Date.now() */
|
|
87
|
-
static now() { return new BeTimePoint(Date.now()); }
|
|
88
|
-
/** Create a BeTimePoint at a specified duration in the future from now
|
|
89
|
-
* @param val the duration from now
|
|
90
|
-
*/
|
|
91
|
-
static fromNow(val) { return new BeTimePoint(Date.now() + val.milliseconds); }
|
|
92
|
-
/** Create a BeTimePoint at a specified duration in the past before now
|
|
93
|
-
* @param val the duration before now
|
|
94
|
-
*/
|
|
95
|
-
static beforeNow(val) { return new BeTimePoint(Date.now() - val.milliseconds); }
|
|
96
|
-
/** Determine whether this BeTimePoint is a time in the future from the time this method is called (it calls now()!) */
|
|
97
|
-
get isInFuture() { return Date.now() < this._milliseconds; }
|
|
98
|
-
/** Determine whether this BeTimePoint is a time that has already passed before the time this method is called (it calls now()!) */
|
|
99
|
-
get isInPast() { return Date.now() > this._milliseconds; }
|
|
100
|
-
/** Determine whether this BeTimePoint happens before another one.
|
|
101
|
-
* @param other the other BeTimePoint.
|
|
102
|
-
*/
|
|
103
|
-
before(other) { return this._milliseconds < other._milliseconds; }
|
|
104
|
-
/** Determine whether this BeTimePoint happens after another one.
|
|
105
|
-
* @param other the other BeTimePoint.
|
|
106
|
-
*/
|
|
107
|
-
after(other) { return this._milliseconds > other._milliseconds; }
|
|
108
|
-
/** Subtract a BeDuration from this BeTimePoint, returning a new BeTimePoint. This moves this BeTimePoint backwards in time if BeDuration.isTowardsFuture() === true
|
|
109
|
-
* @param duration the duration to subtract.
|
|
110
|
-
*/
|
|
111
|
-
minus(duration) { return new BeTimePoint(this._milliseconds - duration.milliseconds); }
|
|
112
|
-
/** Subtract a BeDuration from this BeTimePoint, returning a new BeTimePoint. This moves this BeTimePoint backwards in time if BeDuration.isTowardsFuture() === true
|
|
113
|
-
* @param duration the duration to subtract.
|
|
114
|
-
*/
|
|
115
|
-
plus(duration) { return new BeTimePoint(this._milliseconds + duration.milliseconds); }
|
|
116
|
-
}
|
|
117
|
-
exports.BeTimePoint = BeTimePoint;
|
|
118
|
-
/** A StopWatch for timing operations.
|
|
119
|
-
* @public
|
|
120
|
-
*/
|
|
121
|
-
class StopWatch {
|
|
122
|
-
/**
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
/** Start the stopwatch. Any future time measurements will be based on this new value. */
|
|
140
|
-
start() {
|
|
141
|
-
this.reset();
|
|
142
|
-
this._start = BeTimePoint.now();
|
|
143
|
-
}
|
|
144
|
-
/** Stop the stopwatch so that the duration can be viewed later. */
|
|
145
|
-
stop() {
|
|
146
|
-
this._stop = BeTimePoint.now();
|
|
147
|
-
return this.elapsed;
|
|
148
|
-
}
|
|
149
|
-
/** Clear the StopWatch */
|
|
150
|
-
reset() { this._start = this._stop = undefined; }
|
|
151
|
-
}
|
|
152
|
-
exports.StopWatch = StopWatch;
|
|
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.StopWatch = exports.BeTimePoint = exports.BeDuration = void 0;
|
|
11
|
+
/** A duration of time. Can be either positive (towards future) or negative (in the past).
|
|
12
|
+
* BeDurations are immutable.
|
|
13
|
+
* @public
|
|
14
|
+
*/
|
|
15
|
+
class BeDuration {
|
|
16
|
+
constructor(milliseconds = 0) { this._milliseconds = milliseconds; }
|
|
17
|
+
/** The duration in milliseconds */
|
|
18
|
+
get milliseconds() { return this._milliseconds; }
|
|
19
|
+
get seconds() { return this._milliseconds / 1000; }
|
|
20
|
+
/** Create a BeDuration from seconds.
|
|
21
|
+
* @param seconds the number of seconds for this BeDuration
|
|
22
|
+
*/
|
|
23
|
+
static fromSeconds(seconds) { return new BeDuration(seconds * 1000); }
|
|
24
|
+
/** Create a BeDuration from milliseconds.
|
|
25
|
+
* @param milliseconds the number of milliseconds for this BeDuration
|
|
26
|
+
*/
|
|
27
|
+
static fromMilliseconds(milliseconds) { return new BeDuration(milliseconds); }
|
|
28
|
+
/** Determine whether this BeDuration is 0 seconds */
|
|
29
|
+
get isZero() { return this._milliseconds === 0; }
|
|
30
|
+
/** Determine whether this BeDuration is towards the future */
|
|
31
|
+
get isTowardsFuture() { return this._milliseconds > 0; }
|
|
32
|
+
/** Determine whether this BeDuration is towards the past */
|
|
33
|
+
get isTowardsPast() { return this._milliseconds < 0; }
|
|
34
|
+
/** Subtract a BeDuration from this BeDuration, returning a new BeDuration. */
|
|
35
|
+
minus(other) { return new BeDuration(this._milliseconds - other._milliseconds); }
|
|
36
|
+
/** Add a BeDuration to this BeDuration, returning a new BeDuration */
|
|
37
|
+
plus(other) { return new BeDuration(this._milliseconds + other._milliseconds); }
|
|
38
|
+
/** Utility function to just wait for the specified time
|
|
39
|
+
* @param ms Duration in milliseconds to wait
|
|
40
|
+
* @return Promise that resolves after the specified wait period
|
|
41
|
+
*/
|
|
42
|
+
static async wait(ms) {
|
|
43
|
+
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
44
|
+
}
|
|
45
|
+
/** Utility function to wait for either the specified time or a promise, whichever resolves first
|
|
46
|
+
* @param ms Maximum duration in milliseconds to wait
|
|
47
|
+
* @param promise A pending promise to wait for
|
|
48
|
+
* @return Promise that resolves after the specified wait period or the provided promise resolves, whichever comes first
|
|
49
|
+
*/
|
|
50
|
+
static async race(ms, promise) {
|
|
51
|
+
let timeout;
|
|
52
|
+
const waitPromise = new Promise((resolve) => {
|
|
53
|
+
timeout = setTimeout(resolve, ms);
|
|
54
|
+
});
|
|
55
|
+
return Promise.race([waitPromise, promise]).finally(() => {
|
|
56
|
+
if (timeout)
|
|
57
|
+
clearTimeout(timeout);
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
/** Utility function to just wait for the specified time
|
|
61
|
+
* @return Promise that resolves after the specified wait period
|
|
62
|
+
*/
|
|
63
|
+
async wait() {
|
|
64
|
+
return new Promise((resolve) => setTimeout(resolve, this._milliseconds));
|
|
65
|
+
}
|
|
66
|
+
/** Execute a function after delaying by this duration.
|
|
67
|
+
* @param fn the function to execute after the delay
|
|
68
|
+
* @param scope An optional object scope to serve as the 'this' pointer when `fn` is invoked.
|
|
69
|
+
* @param args optional arguments to `fn`
|
|
70
|
+
* @return Promise resolved by `fn`
|
|
71
|
+
*/
|
|
72
|
+
async executeAfter(fn, scope, ...args) {
|
|
73
|
+
return new Promise((resolve) => setTimeout(() => resolve(fn.apply(scope, args)), this._milliseconds));
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
exports.BeDuration = BeDuration;
|
|
77
|
+
/** A specific point in time relative to the current time.
|
|
78
|
+
* BeTimePoints are used for timing operations. They are created from a BeDuration relative to the "now".
|
|
79
|
+
* BeTimePoints are immutable.
|
|
80
|
+
* @public
|
|
81
|
+
*/
|
|
82
|
+
class BeTimePoint {
|
|
83
|
+
/** the time in milliseconds, of this BeTimePoint (relative to January 1, 1970 00:00:00 UTC.) */
|
|
84
|
+
get milliseconds() { return this._milliseconds; }
|
|
85
|
+
constructor(milliseconds) { this._milliseconds = milliseconds; }
|
|
86
|
+
/** Create a BeTimePoint from Date.now() */
|
|
87
|
+
static now() { return new BeTimePoint(Date.now()); }
|
|
88
|
+
/** Create a BeTimePoint at a specified duration in the future from now
|
|
89
|
+
* @param val the duration from now
|
|
90
|
+
*/
|
|
91
|
+
static fromNow(val) { return new BeTimePoint(Date.now() + val.milliseconds); }
|
|
92
|
+
/** Create a BeTimePoint at a specified duration in the past before now
|
|
93
|
+
* @param val the duration before now
|
|
94
|
+
*/
|
|
95
|
+
static beforeNow(val) { return new BeTimePoint(Date.now() - val.milliseconds); }
|
|
96
|
+
/** Determine whether this BeTimePoint is a time in the future from the time this method is called (it calls now()!) */
|
|
97
|
+
get isInFuture() { return Date.now() < this._milliseconds; }
|
|
98
|
+
/** Determine whether this BeTimePoint is a time that has already passed before the time this method is called (it calls now()!) */
|
|
99
|
+
get isInPast() { return Date.now() > this._milliseconds; }
|
|
100
|
+
/** Determine whether this BeTimePoint happens before another one.
|
|
101
|
+
* @param other the other BeTimePoint.
|
|
102
|
+
*/
|
|
103
|
+
before(other) { return this._milliseconds < other._milliseconds; }
|
|
104
|
+
/** Determine whether this BeTimePoint happens after another one.
|
|
105
|
+
* @param other the other BeTimePoint.
|
|
106
|
+
*/
|
|
107
|
+
after(other) { return this._milliseconds > other._milliseconds; }
|
|
108
|
+
/** Subtract a BeDuration from this BeTimePoint, returning a new BeTimePoint. This moves this BeTimePoint backwards in time if BeDuration.isTowardsFuture() === true
|
|
109
|
+
* @param duration the duration to subtract.
|
|
110
|
+
*/
|
|
111
|
+
minus(duration) { return new BeTimePoint(this._milliseconds - duration.milliseconds); }
|
|
112
|
+
/** Subtract a BeDuration from this BeTimePoint, returning a new BeTimePoint. This moves this BeTimePoint backwards in time if BeDuration.isTowardsFuture() === true
|
|
113
|
+
* @param duration the duration to subtract.
|
|
114
|
+
*/
|
|
115
|
+
plus(duration) { return new BeTimePoint(this._milliseconds + duration.milliseconds); }
|
|
116
|
+
}
|
|
117
|
+
exports.BeTimePoint = BeTimePoint;
|
|
118
|
+
/** A StopWatch for timing operations.
|
|
119
|
+
* @public
|
|
120
|
+
*/
|
|
121
|
+
class StopWatch {
|
|
122
|
+
/** Get the elapsed time since start() on a running timer. */
|
|
123
|
+
get current() { return BeDuration.fromMilliseconds(BeTimePoint.now().milliseconds - (!!this._start ? this._start.milliseconds : 0)); }
|
|
124
|
+
/** Get the elapsed time, in seconds, since start() on a running timer. */
|
|
125
|
+
get currentSeconds() { return this.current.seconds; }
|
|
126
|
+
/** Get the elapsed time between start() and stop() on this timer in milliseconds. */
|
|
127
|
+
get elapsed() { return BeDuration.fromMilliseconds((!!this._stop ? this._stop.milliseconds : BeTimePoint.now().milliseconds) - (!!this._start ? this._start.milliseconds : 0)); }
|
|
128
|
+
/** Get the elapsed time, in seconds, between start() and stop() on this timer. */
|
|
129
|
+
get elapsedSeconds() { return this.elapsed.seconds; }
|
|
130
|
+
/** ctor for StopWatch
|
|
131
|
+
* @param description optional string stored with the StopWatch
|
|
132
|
+
* @param startImmediately if true, StopWatch is started when created. Otherwise, call start() explicitly.
|
|
133
|
+
*/
|
|
134
|
+
constructor(description, startImmediately = false) {
|
|
135
|
+
this.description = description;
|
|
136
|
+
if (startImmediately)
|
|
137
|
+
this.start();
|
|
138
|
+
}
|
|
139
|
+
/** Start the stopwatch. Any future time measurements will be based on this new value. */
|
|
140
|
+
start() {
|
|
141
|
+
this.reset();
|
|
142
|
+
this._start = BeTimePoint.now();
|
|
143
|
+
}
|
|
144
|
+
/** Stop the stopwatch so that the duration can be viewed later. */
|
|
145
|
+
stop() {
|
|
146
|
+
this._stop = BeTimePoint.now();
|
|
147
|
+
return this.elapsed;
|
|
148
|
+
}
|
|
149
|
+
/** Clear the StopWatch */
|
|
150
|
+
reset() { this._start = this._stop = undefined; }
|
|
151
|
+
}
|
|
152
|
+
exports.StopWatch = StopWatch;
|
|
153
153
|
//# sourceMappingURL=Time.js.map
|
package/lib/cjs/Time.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Time.js","sourceRoot":"","sources":["../../src/Time.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;AAC/F;;GAEG;;;AAEH;;;GAGG;AACH,MAAa,UAAU;IAErB,YAAoB,eAAuB,CAAC,IAAI,IAAI,CAAC,aAAa,GAAG,YAAY,CAAC,CAAC,CAAC;IAEpF,mCAAmC;IACnC,IAAW,YAAY,KAAK,OAAO,IAAI,CAAC,aAAa,CAAC,CAAC,CAAC;IACxD,IAAW,OAAO,KAAK,OAAO,IAAI,CAAC,aAAa,GAAG,IAAI,CAAC,CAAC,CAAC;IAE1D;;OAE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1E,IAAW,cAAc,KAAa,OAAO,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC;IACpE,qFAAqF;IACrF,IAAW,OAAO,KAAiB,OAAO,UAAU,CAAC,gBAAgB,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,YAAY,CAAC,CAAC,CAAC,WAAW,CAAC,GAAG,EAAE,CAAC,YAAY,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;IACpM,mFAAmF;IACnF,IAAW,cAAc,KAAa,OAAO,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC;IAUpE,yFAAyF;IAClF,KAAK;QACV,IAAI,CAAC,KAAK,EAAE,CAAC;QACb,IAAI,CAAC,MAAM,GAAG,WAAW,CAAC,GAAG,EAAE,CAAC;IAClC,CAAC;IAED,mEAAmE;IAC5D,IAAI;QACT,IAAI,CAAC,KAAK,GAAG,WAAW,CAAC,GAAG,EAAE,CAAC;QAC/B,OAAO,IAAI,CAAC,OAAO,CAAC;IACtB,CAAC;IAED,0BAA0B;IACnB,KAAK,KAAW,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC,KAAK,GAAG,SAAS,CAAC,CAAC,CAAC;CAC/D;AAlCD,8BAkCC","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/** A duration of time. Can be either positive (towards future) or negative (in the past).\r\n * BeDurations are immutable.\r\n * @public\r\n */\r\nexport class BeDuration {\r\n private readonly _milliseconds: number;\r\n private constructor(milliseconds: number = 0) { this._milliseconds = milliseconds; }\r\n\r\n /** The duration in milliseconds */\r\n public get milliseconds() { return this._milliseconds; }\r\n public get seconds() { return this._milliseconds / 1000; }\r\n\r\n /** Create a BeDuration from seconds.\r\n * @param seconds the number of seconds for this BeDuration\r\n */\r\n public static fromSeconds(seconds: number) { return new BeDuration(seconds * 1000); }\r\n /** Create a BeDuration from milliseconds.\r\n * @param milliseconds the number of milliseconds for this BeDuration\r\n */\r\n public static fromMilliseconds(milliseconds: number) { return new BeDuration(milliseconds); }\r\n /** Determine whether this BeDuration is 0 seconds */\r\n public get isZero() { return this._milliseconds === 0; }\r\n /** Determine whether this BeDuration is towards the future */\r\n public get isTowardsFuture(): boolean { return this._milliseconds > 0; }\r\n /** Determine whether this BeDuration is towards the past */\r\n public get isTowardsPast(): boolean { return this._milliseconds < 0; }\r\n /** Subtract a BeDuration from this BeDuration, returning a new BeDuration. */\r\n public minus(other: BeDuration): BeDuration { return new BeDuration(this._milliseconds - other._milliseconds); }\r\n /** Add a BeDuration to this BeDuration, returning a new BeDuration */\r\n public plus(other: BeDuration): BeDuration { return new BeDuration(this._milliseconds + other._milliseconds); }\r\n\r\n /** Utility function to just wait for the specified time\r\n * @param ms Duration in milliseconds to wait\r\n * @return Promise that resolves after the specified wait period\r\n */\r\n public static async wait(ms: number): Promise<void> {\r\n return new Promise<void>((resolve: any) => setTimeout(resolve, ms));\r\n }\r\n\r\n /** Utility function to wait for either the specified time or a promise, whichever resolves first\r\n * @param ms Maximum duration in milliseconds to wait\r\n * @param promise A pending promise to wait for\r\n * @return Promise that resolves after the specified wait period or the provided promise resolves, whichever comes first\r\n */\r\n public static async race<T>(ms: number, promise: PromiseLike<T>): Promise<T | void> {\r\n let timeout: any;\r\n const waitPromise = new Promise<void>((resolve) => {\r\n timeout = setTimeout(resolve, ms);\r\n });\r\n return Promise.race([waitPromise, promise]).finally(() => {\r\n if (timeout)\r\n clearTimeout(timeout);\r\n });\r\n }\r\n\r\n /** Utility function to just wait for the specified time\r\n * @return Promise that resolves after the specified wait period\r\n */\r\n public async wait(): Promise<void> {\r\n return new Promise<void>((resolve: any) => setTimeout(resolve, this._milliseconds));\r\n }\r\n\r\n /** Execute a function after delaying by this duration.\r\n * @param fn the function to execute after the delay\r\n * @param scope An optional object scope to serve as the 'this' pointer when `fn` is invoked.\r\n * @param args optional arguments to `fn`\r\n * @return Promise resolved by `fn`\r\n */\r\n public async executeAfter<T>(fn: (...args: any[]) => T, scope?: any, ...args: any[]): Promise<T> {\r\n return new Promise<T>((resolve: any) => setTimeout(() => resolve(fn.apply(scope, args)), this._milliseconds));\r\n }\r\n}\r\n\r\n/** A specific point in time relative to the current time.\r\n * BeTimePoints are used for timing operations. They are created from a BeDuration relative to the \"now\".\r\n * BeTimePoints are immutable.\r\n * @public\r\n */\r\nexport class BeTimePoint {\r\n private readonly _milliseconds: number;\r\n /** the time in milliseconds, of this BeTimePoint (relative to January 1, 1970 00:00:00 UTC.) */\r\n public get milliseconds() { return this._milliseconds; }\r\n private constructor(milliseconds: number) { this._milliseconds = milliseconds; }\r\n\r\n /** Create a BeTimePoint from Date.now() */\r\n public static now() { return new BeTimePoint(Date.now()); }\r\n\r\n /** Create a BeTimePoint at a specified duration in the future from now\r\n * @param val the duration from now\r\n */\r\n public static fromNow(val: BeDuration) { return new BeTimePoint(Date.now() + val.milliseconds); }\r\n\r\n /** Create a BeTimePoint at a specified duration in the past before now\r\n * @param val the duration before now\r\n */\r\n public static beforeNow(val: BeDuration) { return new BeTimePoint(Date.now() - val.milliseconds); }\r\n\r\n /** Determine whether this BeTimePoint is a time in the future from the time this method is called (it calls now()!) */\r\n public get isInFuture(): boolean { return Date.now() < this._milliseconds; }\r\n\r\n /** Determine whether this BeTimePoint is a time that has already passed before the time this method is called (it calls now()!) */\r\n public get isInPast(): boolean { return Date.now() > this._milliseconds; }\r\n\r\n /** Determine whether this BeTimePoint happens before another one.\r\n * @param other the other BeTimePoint.\r\n */\r\n public before(other: BeTimePoint): boolean { return this._milliseconds < other._milliseconds; }\r\n\r\n /** Determine whether this BeTimePoint happens after another one.\r\n * @param other the other BeTimePoint.\r\n */\r\n public after(other: BeTimePoint): boolean { return this._milliseconds > other._milliseconds; }\r\n\r\n /** Subtract a BeDuration from this BeTimePoint, returning a new BeTimePoint. This moves this BeTimePoint backwards in time if BeDuration.isTowardsFuture() === true\r\n * @param duration the duration to subtract.\r\n */\r\n public minus(duration: BeDuration): BeTimePoint { return new BeTimePoint(this._milliseconds - duration.milliseconds); }\r\n\r\n /** Subtract a BeDuration from this BeTimePoint, returning a new BeTimePoint. This moves this BeTimePoint backwards in time if BeDuration.isTowardsFuture() === true\r\n * @param duration the duration to subtract.\r\n */\r\n public plus(duration: BeDuration) { return new BeTimePoint(this._milliseconds + duration.milliseconds); }\r\n}\r\n\r\n/** A StopWatch for timing operations.\r\n * @public\r\n */\r\nexport class StopWatch {\r\n private _start?: BeTimePoint;\r\n private _stop?: BeTimePoint;\r\n /** Get the elapsed time since start() on a running timer. */\r\n public get current(): BeDuration { return BeDuration.fromMilliseconds(BeTimePoint.now().milliseconds - (!!this._start ? this._start.milliseconds : 0)); }\r\n /** Get the elapsed time, in seconds, since start() on a running timer. */\r\n public get currentSeconds(): number { return this.current.seconds; }\r\n /** Get the elapsed time between start() and stop() on this timer in milliseconds. */\r\n public get elapsed(): BeDuration { return BeDuration.fromMilliseconds((!!this._stop ? this._stop.milliseconds : BeTimePoint.now().milliseconds) - (!!this._start ? this._start.milliseconds : 0)); }\r\n /** Get the elapsed time, in seconds, between start() and stop() on this timer. */\r\n public get elapsedSeconds(): number { return this.elapsed.seconds; }\r\n /** ctor for StopWatch\r\n * @param description optional string stored with the StopWatch\r\n * @param startImmediately if true, StopWatch is started when created. Otherwise, call start() explicitly.\r\n */\r\n constructor(public description?: string, startImmediately = false) {\r\n if (startImmediately)\r\n this.start();\r\n }\r\n\r\n /** Start the stopwatch. Any future time measurements will be based on this new value. */\r\n public start(): void {\r\n this.reset();\r\n this._start = BeTimePoint.now();\r\n }\r\n\r\n /** Stop the stopwatch so that the duration can be viewed later. */\r\n public stop(): BeDuration {\r\n this._stop = BeTimePoint.now();\r\n return this.elapsed;\r\n }\r\n\r\n /** Clear the StopWatch */\r\n public reset(): void { this._start = this._stop = undefined; }\r\n}\r\n"]}
|
|
1
|
+
{"version":3,"file":"Time.js","sourceRoot":"","sources":["../../src/Time.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;AAC/F;;GAEG;;;AAEH;;;GAGG;AACH,MAAa,UAAU;IAErB,YAAoB,eAAuB,CAAC,IAAI,IAAI,CAAC,aAAa,GAAG,YAAY,CAAC,CAAC,CAAC;IAEpF,mCAAmC;IACnC,IAAW,YAAY,KAAK,OAAO,IAAI,CAAC,aAAa,CAAC,CAAC,CAAC;IACxD,IAAW,OAAO,KAAK,OAAO,IAAI,CAAC,aAAa,GAAG,IAAI,CAAC,CAAC,CAAC;IAE1D;;OAEG;IACI,MAAM,CAAC,WAAW,CAAC,OAAe,IAAI,OAAO,IAAI,UAAU,CAAC,OAAO,GAAG,IAAI,CAAC,CAAC,CAAC,CAAC;IACrF;;OAEG;IACI,MAAM,CAAC,gBAAgB,CAAC,YAAoB,IAAI,OAAO,IAAI,UAAU,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC;IAC7F,qDAAqD;IACrD,IAAW,MAAM,KAAK,OAAO,IAAI,CAAC,aAAa,KAAK,CAAC,CAAC,CAAC,CAAC;IACxD,8DAA8D;IAC9D,IAAW,eAAe,KAAc,OAAO,IAAI,CAAC,aAAa,GAAG,CAAC,CAAC,CAAC,CAAC;IACxE,4DAA4D;IAC5D,IAAW,aAAa,KAAc,OAAO,IAAI,CAAC,aAAa,GAAG,CAAC,CAAC,CAAC,CAAC;IACtE,8EAA8E;IACvE,KAAK,CAAC,KAAiB,IAAgB,OAAO,IAAI,UAAU,CAAC,IAAI,CAAC,aAAa,GAAG,KAAK,CAAC,aAAa,CAAC,CAAC,CAAC,CAAC;IAChH,sEAAsE;IAC/D,IAAI,CAAC,KAA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5D,IAAI;QACT,IAAI,CAAC,KAAK,GAAG,WAAW,CAAC,GAAG,EAAE,CAAC;QAC/B,OAAO,IAAI,CAAC,OAAO,CAAC;IACtB,CAAC;IAED,0BAA0B;IACnB,KAAK,KAAW,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC,KAAK,GAAG,SAAS,CAAC,CAAC,CAAC;CAC/D;AAlCD,8BAkCC","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/** A duration of time. Can be either positive (towards future) or negative (in the past).\r\n * BeDurations are immutable.\r\n * @public\r\n */\r\nexport class BeDuration {\r\n private readonly _milliseconds: number;\r\n private constructor(milliseconds: number = 0) { this._milliseconds = milliseconds; }\r\n\r\n /** The duration in milliseconds */\r\n public get milliseconds() { return this._milliseconds; }\r\n public get seconds() { return this._milliseconds / 1000; }\r\n\r\n /** Create a BeDuration from seconds.\r\n * @param seconds the number of seconds for this BeDuration\r\n */\r\n public static fromSeconds(seconds: number) { return new BeDuration(seconds * 1000); }\r\n /** Create a BeDuration from milliseconds.\r\n * @param milliseconds the number of milliseconds for this BeDuration\r\n */\r\n public static fromMilliseconds(milliseconds: number) { return new BeDuration(milliseconds); }\r\n /** Determine whether this BeDuration is 0 seconds */\r\n public get isZero() { return this._milliseconds === 0; }\r\n /** Determine whether this BeDuration is towards the future */\r\n public get isTowardsFuture(): boolean { return this._milliseconds > 0; }\r\n /** Determine whether this BeDuration is towards the past */\r\n public get isTowardsPast(): boolean { return this._milliseconds < 0; }\r\n /** Subtract a BeDuration from this BeDuration, returning a new BeDuration. */\r\n public minus(other: BeDuration): BeDuration { return new BeDuration(this._milliseconds - other._milliseconds); }\r\n /** Add a BeDuration to this BeDuration, returning a new BeDuration */\r\n public plus(other: BeDuration): BeDuration { return new BeDuration(this._milliseconds + other._milliseconds); }\r\n\r\n /** Utility function to just wait for the specified time\r\n * @param ms Duration in milliseconds to wait\r\n * @return Promise that resolves after the specified wait period\r\n */\r\n public static async wait(ms: number): Promise<void> {\r\n return new Promise<void>((resolve: any) => setTimeout(resolve, ms));\r\n }\r\n\r\n /** Utility function to wait for either the specified time or a promise, whichever resolves first\r\n * @param ms Maximum duration in milliseconds to wait\r\n * @param promise A pending promise to wait for\r\n * @return Promise that resolves after the specified wait period or the provided promise resolves, whichever comes first\r\n */\r\n public static async race<T>(ms: number, promise: PromiseLike<T>): Promise<T | void> {\r\n let timeout: any;\r\n const waitPromise = new Promise<void>((resolve) => {\r\n timeout = setTimeout(resolve, ms);\r\n });\r\n return Promise.race([waitPromise, promise]).finally(() => {\r\n if (timeout)\r\n clearTimeout(timeout);\r\n });\r\n }\r\n\r\n /** Utility function to just wait for the specified time\r\n * @return Promise that resolves after the specified wait period\r\n */\r\n public async wait(): Promise<void> {\r\n return new Promise<void>((resolve: any) => setTimeout(resolve, this._milliseconds));\r\n }\r\n\r\n /** Execute a function after delaying by this duration.\r\n * @param fn the function to execute after the delay\r\n * @param scope An optional object scope to serve as the 'this' pointer when `fn` is invoked.\r\n * @param args optional arguments to `fn`\r\n * @return Promise resolved by `fn`\r\n */\r\n public async executeAfter<T>(fn: (...args: any[]) => T, scope?: any, ...args: any[]): Promise<T> {\r\n return new Promise<T>((resolve: any) => setTimeout(() => resolve(fn.apply(scope, args)), this._milliseconds));\r\n }\r\n}\r\n\r\n/** A specific point in time relative to the current time.\r\n * BeTimePoints are used for timing operations. They are created from a BeDuration relative to the \"now\".\r\n * BeTimePoints are immutable.\r\n * @public\r\n */\r\nexport class BeTimePoint {\r\n private readonly _milliseconds: number;\r\n /** the time in milliseconds, of this BeTimePoint (relative to January 1, 1970 00:00:00 UTC.) */\r\n public get milliseconds() { return this._milliseconds; }\r\n private constructor(milliseconds: number) { this._milliseconds = milliseconds; }\r\n\r\n /** Create a BeTimePoint from Date.now() */\r\n public static now() { return new BeTimePoint(Date.now()); }\r\n\r\n /** Create a BeTimePoint at a specified duration in the future from now\r\n * @param val the duration from now\r\n */\r\n public static fromNow(val: BeDuration) { return new BeTimePoint(Date.now() + val.milliseconds); }\r\n\r\n /** Create a BeTimePoint at a specified duration in the past before now\r\n * @param val the duration before now\r\n */\r\n public static beforeNow(val: BeDuration) { return new BeTimePoint(Date.now() - val.milliseconds); }\r\n\r\n /** Determine whether this BeTimePoint is a time in the future from the time this method is called (it calls now()!) */\r\n public get isInFuture(): boolean { return Date.now() < this._milliseconds; }\r\n\r\n /** Determine whether this BeTimePoint is a time that has already passed before the time this method is called (it calls now()!) */\r\n public get isInPast(): boolean { return Date.now() > this._milliseconds; }\r\n\r\n /** Determine whether this BeTimePoint happens before another one.\r\n * @param other the other BeTimePoint.\r\n */\r\n public before(other: BeTimePoint): boolean { return this._milliseconds < other._milliseconds; }\r\n\r\n /** Determine whether this BeTimePoint happens after another one.\r\n * @param other the other BeTimePoint.\r\n */\r\n public after(other: BeTimePoint): boolean { return this._milliseconds > other._milliseconds; }\r\n\r\n /** Subtract a BeDuration from this BeTimePoint, returning a new BeTimePoint. This moves this BeTimePoint backwards in time if BeDuration.isTowardsFuture() === true\r\n * @param duration the duration to subtract.\r\n */\r\n public minus(duration: BeDuration): BeTimePoint { return new BeTimePoint(this._milliseconds - duration.milliseconds); }\r\n\r\n /** Subtract a BeDuration from this BeTimePoint, returning a new BeTimePoint. This moves this BeTimePoint backwards in time if BeDuration.isTowardsFuture() === true\r\n * @param duration the duration to subtract.\r\n */\r\n public plus(duration: BeDuration) { return new BeTimePoint(this._milliseconds + duration.milliseconds); }\r\n}\r\n\r\n/** A StopWatch for timing operations.\r\n * @public\r\n */\r\nexport class StopWatch {\r\n private _start?: BeTimePoint;\r\n private _stop?: BeTimePoint;\r\n /** Get the elapsed time since start() on a running timer. */\r\n public get current(): BeDuration { return BeDuration.fromMilliseconds(BeTimePoint.now().milliseconds - (!!this._start ? this._start.milliseconds : 0)); }\r\n /** Get the elapsed time, in seconds, since start() on a running timer. */\r\n public get currentSeconds(): number { return this.current.seconds; }\r\n /** Get the elapsed time between start() and stop() on this timer in milliseconds. */\r\n public get elapsed(): BeDuration { return BeDuration.fromMilliseconds((!!this._stop ? this._stop.milliseconds : BeTimePoint.now().milliseconds) - (!!this._start ? this._start.milliseconds : 0)); }\r\n /** Get the elapsed time, in seconds, between start() and stop() on this timer. */\r\n public get elapsedSeconds(): number { return this.elapsed.seconds; }\r\n /** ctor for StopWatch\r\n * @param description optional string stored with the StopWatch\r\n * @param startImmediately if true, StopWatch is started when created. Otherwise, call start() explicitly.\r\n */\r\n constructor(public description?: string, startImmediately = false) {\r\n if (startImmediately)\r\n this.start();\r\n }\r\n\r\n /** Start the stopwatch. Any future time measurements will be based on this new value. */\r\n public start(): void {\r\n this.reset();\r\n this._start = BeTimePoint.now();\r\n }\r\n\r\n /** Stop the stopwatch so that the duration can be viewed later. */\r\n public stop(): BeDuration {\r\n this._stop = BeTimePoint.now();\r\n return this.elapsed;\r\n }\r\n\r\n /** Clear the StopWatch */\r\n public reset(): void { this._start = this._stop = undefined; }\r\n}\r\n"]}
|