@fluidframework/core-utils 2.0.0-dev.7.4.0.217884 → 2.0.0-dev.7.4.0.221926
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 +4 -0
- package/api-extractor.json +0 -3
- package/api-report/core-utils.api.md +4 -4
- package/dist/core-utils-alpha.d.ts +119 -6
- package/dist/core-utils-untrimmed.d.ts +4 -4
- package/dist/promiseCache.d.ts +3 -3
- package/dist/promiseCache.js +1 -1
- package/dist/promiseCache.js.map +1 -1
- package/dist/promises.d.ts +1 -1
- package/dist/promises.js +1 -1
- package/dist/promises.js.map +1 -1
- package/lib/assert.js +5 -1
- package/lib/assert.js.map +1 -1
- package/lib/compare.js +5 -1
- package/lib/compare.js.map +1 -1
- package/lib/core-utils-alpha.d.ts +119 -6
- package/lib/core-utils-untrimmed.d.ts +4 -4
- package/lib/delay.js +5 -1
- package/lib/delay.js.map +1 -1
- package/lib/heap.js +6 -2
- package/lib/heap.js.map +1 -1
- package/lib/index.js +25 -9
- package/lib/index.js.map +1 -1
- package/lib/lazy.js +7 -2
- package/lib/lazy.js.map +1 -1
- package/lib/promiseCache.d.ts +3 -3
- package/lib/promiseCache.js +6 -2
- package/lib/promiseCache.js.map +1 -1
- package/lib/promises.d.ts +1 -1
- package/lib/promises.js +6 -2
- package/lib/promises.js.map +1 -1
- package/lib/timer.js +14 -8
- package/lib/timer.js.map +1 -1
- package/lib/unreachable.js +5 -1
- package/lib/unreachable.js.map +1 -1
- package/package.json +4 -2
- package/src/promiseCache.ts +3 -3
- package/src/promises.ts +1 -1
package/CHANGELOG.md
CHANGED
package/api-extractor.json
CHANGED
|
@@ -1,9 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"$schema": "https://developer.microsoft.com/json-schemas/api-extractor/v7/api-extractor.schema.json",
|
|
3
3
|
"extends": "../../../common/build/build-common/api-extractor-base.json",
|
|
4
|
-
"dtsRollup": {
|
|
5
|
-
"enabled": true
|
|
6
|
-
},
|
|
7
4
|
"messages": {
|
|
8
5
|
"extractorMessageReporting": {
|
|
9
6
|
// TODO: Add missing documentation and remove this rule override
|
|
@@ -10,7 +10,7 @@ export function assert(condition: boolean, message: string | number): asserts co
|
|
|
10
10
|
// @internal
|
|
11
11
|
export const compareArrays: <T>(left: readonly T[], right: readonly T[], comparator?: (leftItem: T, rightItem: T, index: number) => boolean) => boolean;
|
|
12
12
|
|
|
13
|
-
// @
|
|
13
|
+
// @alpha
|
|
14
14
|
export class Deferred<T> {
|
|
15
15
|
constructor();
|
|
16
16
|
get isCompleted(): boolean;
|
|
@@ -90,7 +90,7 @@ export class LazyPromise<T> implements Promise<T> {
|
|
|
90
90
|
// @internal
|
|
91
91
|
export const NumberComparer: IComparer<number>;
|
|
92
92
|
|
|
93
|
-
// @
|
|
93
|
+
// @alpha
|
|
94
94
|
export class PromiseCache<TKey, TResult> {
|
|
95
95
|
constructor({ expiry, removeOnError, }?: PromiseCacheOptions);
|
|
96
96
|
add(key: TKey, asyncFn: () => Promise<TResult>): boolean;
|
|
@@ -102,7 +102,7 @@ export class PromiseCache<TKey, TResult> {
|
|
|
102
102
|
remove(key: TKey): boolean;
|
|
103
103
|
}
|
|
104
104
|
|
|
105
|
-
// @
|
|
105
|
+
// @alpha
|
|
106
106
|
export type PromiseCacheExpiry = {
|
|
107
107
|
policy: "indefinite";
|
|
108
108
|
} | {
|
|
@@ -110,7 +110,7 @@ export type PromiseCacheExpiry = {
|
|
|
110
110
|
durationMs: number;
|
|
111
111
|
};
|
|
112
112
|
|
|
113
|
-
// @
|
|
113
|
+
// @alpha
|
|
114
114
|
export interface PromiseCacheOptions {
|
|
115
115
|
expiry?: PromiseCacheExpiry;
|
|
116
116
|
removeOnError?: (error: any) => boolean;
|
|
@@ -2,7 +2,39 @@
|
|
|
2
2
|
|
|
3
3
|
/* Excluded from this release type: compareArrays */
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
/**
|
|
6
|
+
* A deferred creates a promise and the ability to resolve or reject it
|
|
7
|
+
* @alpha
|
|
8
|
+
*/
|
|
9
|
+
export declare class Deferred<T> {
|
|
10
|
+
private readonly p;
|
|
11
|
+
private res;
|
|
12
|
+
private rej;
|
|
13
|
+
private completed;
|
|
14
|
+
constructor();
|
|
15
|
+
/**
|
|
16
|
+
* Returns whether the underlying promise has been completed
|
|
17
|
+
*/
|
|
18
|
+
get isCompleted(): boolean;
|
|
19
|
+
/**
|
|
20
|
+
* Retrieves the underlying promise for the deferred
|
|
21
|
+
*
|
|
22
|
+
* @returns the underlying promise
|
|
23
|
+
*/
|
|
24
|
+
get promise(): Promise<T>;
|
|
25
|
+
/**
|
|
26
|
+
* Resolves the promise
|
|
27
|
+
*
|
|
28
|
+
* @param value - the value to resolve the promise with
|
|
29
|
+
*/
|
|
30
|
+
resolve(value: T | PromiseLike<T>): void;
|
|
31
|
+
/**
|
|
32
|
+
* Rejects the promise
|
|
33
|
+
*
|
|
34
|
+
* @param value - the value to reject the promise with
|
|
35
|
+
*/
|
|
36
|
+
reject(error: any): void;
|
|
37
|
+
}
|
|
6
38
|
|
|
7
39
|
/* Excluded from this release type: delay */
|
|
8
40
|
|
|
@@ -24,11 +56,92 @@
|
|
|
24
56
|
|
|
25
57
|
/* Excluded from this release type: NumberComparer */
|
|
26
58
|
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
59
|
+
/**
|
|
60
|
+
* A specialized cache for async work, allowing you to safely cache the promised result of some async work
|
|
61
|
+
* without fear of running it multiple times or losing track of errors.
|
|
62
|
+
* @alpha
|
|
63
|
+
*/
|
|
64
|
+
export declare class PromiseCache<TKey, TResult> {
|
|
65
|
+
private readonly cache;
|
|
66
|
+
private readonly gc;
|
|
67
|
+
private readonly removeOnError;
|
|
68
|
+
/**
|
|
69
|
+
* Create the PromiseCache with the given options, with the following defaults:
|
|
70
|
+
*
|
|
71
|
+
* expiry: indefinite, removeOnError: true for all errors
|
|
72
|
+
*/
|
|
73
|
+
constructor({ expiry, removeOnError, }?: PromiseCacheOptions);
|
|
74
|
+
/**
|
|
75
|
+
* Check if there's anything cached at the given key
|
|
76
|
+
*/
|
|
77
|
+
has(key: TKey): boolean;
|
|
78
|
+
/**
|
|
79
|
+
* Get the Promise for the given key, or undefined if it's not found.
|
|
80
|
+
* Extend expiry if applicable.
|
|
81
|
+
*/
|
|
82
|
+
get(key: TKey): Promise<TResult> | undefined;
|
|
83
|
+
/**
|
|
84
|
+
* Remove the Promise for the given key, returning true if it was found and removed
|
|
85
|
+
*/
|
|
86
|
+
remove(key: TKey): boolean;
|
|
87
|
+
/**
|
|
88
|
+
* Try to add the result of the given asyncFn, without overwriting an existing cache entry at that key.
|
|
89
|
+
* Returns a Promise for the added or existing async work being done at that key.
|
|
90
|
+
* @param key - key name where to store the async work
|
|
91
|
+
* @param asyncFn - the async work to do and store, if not already in progress under the given key
|
|
92
|
+
*/
|
|
93
|
+
addOrGet(key: TKey, asyncFn: () => Promise<TResult>): Promise<TResult>;
|
|
94
|
+
/**
|
|
95
|
+
* Try to add the result of the given asyncFn, without overwriting an existing cache entry at that key.
|
|
96
|
+
* Returns false if the cache already contained an entry at that key, and true otherwise.
|
|
97
|
+
* @param key - key name where to store the async work
|
|
98
|
+
* @param asyncFn - the async work to do and store, if not already in progress under the given key
|
|
99
|
+
*/
|
|
100
|
+
add(key: TKey, asyncFn: () => Promise<TResult>): boolean;
|
|
101
|
+
/**
|
|
102
|
+
* Try to add the given value, without overwriting an existing cache entry at that key.
|
|
103
|
+
* Returns a Promise for the added or existing async work being done at that key.
|
|
104
|
+
* @param key - key name where to store the async work
|
|
105
|
+
* @param value - value to store
|
|
106
|
+
*/
|
|
107
|
+
addValueOrGet(key: TKey, value: TResult): Promise<TResult>;
|
|
108
|
+
/**
|
|
109
|
+
* Try to add the given value, without overwriting an existing cache entry at that key.
|
|
110
|
+
* Returns false if the cache already contained an entry at that key, and true otherwise.
|
|
111
|
+
* @param key - key name where to store the value
|
|
112
|
+
* @param value - value to store
|
|
113
|
+
*/
|
|
114
|
+
addValue(key: TKey, value: TResult): boolean;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
/**
|
|
118
|
+
* Three supported expiry policies:
|
|
119
|
+
* - indefinite: entries don't expire and must be explicitly removed
|
|
120
|
+
* - absolute: entries expire after the given duration in MS, even if accessed multiple times in the mean time
|
|
121
|
+
* - sliding: entries expire after the given duration in MS of inactivity (i.e. get resets the clock)
|
|
122
|
+
* @alpha
|
|
123
|
+
*/
|
|
124
|
+
export declare type PromiseCacheExpiry = {
|
|
125
|
+
policy: "indefinite";
|
|
126
|
+
} | {
|
|
127
|
+
policy: "absolute" | "sliding";
|
|
128
|
+
durationMs: number;
|
|
129
|
+
};
|
|
130
|
+
|
|
131
|
+
/**
|
|
132
|
+
* Options for configuring the {@link PromiseCache}
|
|
133
|
+
* @alpha
|
|
134
|
+
*/
|
|
135
|
+
export declare interface PromiseCacheOptions {
|
|
136
|
+
/**
|
|
137
|
+
* Common expiration policy for all items added to this cache
|
|
138
|
+
*/
|
|
139
|
+
expiry?: PromiseCacheExpiry;
|
|
140
|
+
/**
|
|
141
|
+
* If the stored Promise is rejected with a particular error, should the given key be removed?
|
|
142
|
+
*/
|
|
143
|
+
removeOnError?: (error: any) => boolean;
|
|
144
|
+
}
|
|
32
145
|
|
|
33
146
|
/* Excluded from this release type: PromiseTimer */
|
|
34
147
|
|
|
@@ -25,7 +25,7 @@ export declare const compareArrays: <T>(left: readonly T[], right: readonly T[],
|
|
|
25
25
|
|
|
26
26
|
/**
|
|
27
27
|
* A deferred creates a promise and the ability to resolve or reject it
|
|
28
|
-
* @
|
|
28
|
+
* @alpha
|
|
29
29
|
*/
|
|
30
30
|
export declare class Deferred<T> {
|
|
31
31
|
private readonly p;
|
|
@@ -231,7 +231,7 @@ export declare const NumberComparer: IComparer<number>;
|
|
|
231
231
|
/**
|
|
232
232
|
* A specialized cache for async work, allowing you to safely cache the promised result of some async work
|
|
233
233
|
* without fear of running it multiple times or losing track of errors.
|
|
234
|
-
* @
|
|
234
|
+
* @alpha
|
|
235
235
|
*/
|
|
236
236
|
export declare class PromiseCache<TKey, TResult> {
|
|
237
237
|
private readonly cache;
|
|
@@ -291,7 +291,7 @@ export declare class PromiseCache<TKey, TResult> {
|
|
|
291
291
|
* - indefinite: entries don't expire and must be explicitly removed
|
|
292
292
|
* - absolute: entries expire after the given duration in MS, even if accessed multiple times in the mean time
|
|
293
293
|
* - sliding: entries expire after the given duration in MS of inactivity (i.e. get resets the clock)
|
|
294
|
-
* @
|
|
294
|
+
* @alpha
|
|
295
295
|
*/
|
|
296
296
|
export declare type PromiseCacheExpiry = {
|
|
297
297
|
policy: "indefinite";
|
|
@@ -302,7 +302,7 @@ export declare type PromiseCacheExpiry = {
|
|
|
302
302
|
|
|
303
303
|
/**
|
|
304
304
|
* Options for configuring the {@link PromiseCache}
|
|
305
|
-
* @
|
|
305
|
+
* @alpha
|
|
306
306
|
*/
|
|
307
307
|
export declare interface PromiseCacheOptions {
|
|
308
308
|
/**
|
package/dist/promiseCache.d.ts
CHANGED
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
* - indefinite: entries don't expire and must be explicitly removed
|
|
8
8
|
* - absolute: entries expire after the given duration in MS, even if accessed multiple times in the mean time
|
|
9
9
|
* - sliding: entries expire after the given duration in MS of inactivity (i.e. get resets the clock)
|
|
10
|
-
* @
|
|
10
|
+
* @alpha
|
|
11
11
|
*/
|
|
12
12
|
export type PromiseCacheExpiry = {
|
|
13
13
|
policy: "indefinite";
|
|
@@ -17,7 +17,7 @@ export type PromiseCacheExpiry = {
|
|
|
17
17
|
};
|
|
18
18
|
/**
|
|
19
19
|
* Options for configuring the {@link PromiseCache}
|
|
20
|
-
* @
|
|
20
|
+
* @alpha
|
|
21
21
|
*/
|
|
22
22
|
export interface PromiseCacheOptions {
|
|
23
23
|
/**
|
|
@@ -32,7 +32,7 @@ export interface PromiseCacheOptions {
|
|
|
32
32
|
/**
|
|
33
33
|
* A specialized cache for async work, allowing you to safely cache the promised result of some async work
|
|
34
34
|
* without fear of running it multiple times or losing track of errors.
|
|
35
|
-
* @
|
|
35
|
+
* @alpha
|
|
36
36
|
*/
|
|
37
37
|
export declare class PromiseCache<TKey, TResult> {
|
|
38
38
|
private readonly cache;
|
package/dist/promiseCache.js
CHANGED
|
@@ -50,7 +50,7 @@ class GarbageCollector {
|
|
|
50
50
|
/**
|
|
51
51
|
* A specialized cache for async work, allowing you to safely cache the promised result of some async work
|
|
52
52
|
* without fear of running it multiple times or losing track of errors.
|
|
53
|
-
* @
|
|
53
|
+
* @alpha
|
|
54
54
|
*/
|
|
55
55
|
class PromiseCache {
|
|
56
56
|
/**
|
package/dist/promiseCache.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"promiseCache.js","sourceRoot":"","sources":["../src/promiseCache.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAmCH;;;GAGG;AACH,MAAM,gBAAgB;IAGrB,YACkB,MAA0B,EAC1B,OAA4B;QAD5B,WAAM,GAAN,MAAM,CAAoB;QAC1B,YAAO,GAAP,OAAO,CAAqB;QAJ7B,eAAU,GAAG,IAAI,GAAG,EAAuC,CAAC;IAK1E,CAAC;IAEJ;;OAEG;IACI,QAAQ,CAAC,GAAS;QACxB,IAAI,IAAI,CAAC,MAAM,CAAC,MAAM,KAAK,YAAY,EAAE;YACxC,IAAI,CAAC,UAAU,CAAC,GAAG,CAClB,GAAG,EACH,UAAU,CAAC,GAAG,EAAE;gBACf,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;gBAClB,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;YAClB,CAAC,EAAE,IAAI,CAAC,MAAM,CAAC,UAAU,CAAC,CAC1B,CAAC;SACF;IACF,CAAC;IAED;;OAEG;IACI,MAAM,CAAC,GAAS;QACtB,MAAM,OAAO,GAAG,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,GAAG,CAAC,C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K,CAAC,CAAC;IAC9C,CAAC;IAED;;;;;OAKG;IACI,QAAQ,CAAC,GAAS,EAAE,KAAc;QACxC,OAAO,IAAI,CAAC,GAAG,CAAC,GAAG,EAAE,KAAK,IAAI,EAAE,CAAC,KAAK,CAAC,CAAC;IACzC,CAAC;CACD;AA/GD,oCA+GC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\n/**\n * Three supported expiry policies:\n * - indefinite: entries don't expire and must be explicitly removed\n * - absolute: entries expire after the given duration in MS, even if accessed multiple times in the mean time\n * - sliding: entries expire after the given duration in MS of inactivity (i.e. get resets the clock)\n * @
|
|
1
|
+
{"version":3,"file":"promiseCache.js","sourceRoot":"","sources":["../src/promiseCache.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAmCH;;;GAGG;AACH,MAAM,gBAAgB;IAGrB,YACkB,MAA0B,EAC1B,OAA4B;QAD5B,WAAM,GAAN,MAAM,CAAoB;QAC1B,YAAO,GAAP,OAAO,CAAqB;QAJ7B,eAAU,GAAG,IAAI,GAAG,EAAuC,CAAC;IAK1E,CAAC;IAEJ;;OAEG;IACI,QAAQ,CAAC,GAAS;QACxB,IAAI,IAAI,CAAC,MAAM,CAAC,MAAM,KAAK,YAAY,EAAE;YACxC,IAAI,CAAC,UAAU,CAAC,GAAG,CAClB,GAAG,EACH,UAAU,CAAC,GAAG,EAAE;gBACf,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;gBAClB,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;YAClB,CAAC,EAAE,IAAI,CAAC,MAAM,CAAC,UAAU,CAAC,CAC1B,CAAC;SACF;IACF,CAAC;IAED;;OAEG;IACI,MAAM,CAAC,GAAS;QACtB,MAAM,OAAO,GAAG,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;QACzC,IAAI,OAAO,KAAK,SAAS,EAAE;YAC1B,YAAY,CAAC,O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GAAS,EAAE,KAAc;QACxC,OAAO,IAAI,CAAC,GAAG,CAAC,GAAG,EAAE,KAAK,IAAI,EAAE,CAAC,KAAK,CAAC,CAAC;IACzC,CAAC;CACD;AA/GD,oCA+GC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\n/**\n * Three supported expiry policies:\n * - indefinite: entries don't expire and must be explicitly removed\n * - absolute: entries expire after the given duration in MS, even if accessed multiple times in the mean time\n * - sliding: entries expire after the given duration in MS of inactivity (i.e. get resets the clock)\n * @alpha\n */\nexport type PromiseCacheExpiry =\n\t| {\n\t\t\tpolicy: \"indefinite\";\n\t }\n\t| {\n\t\t\tpolicy: \"absolute\" | \"sliding\";\n\t\t\tdurationMs: number;\n\t };\n\n/**\n * Options for configuring the {@link PromiseCache}\n * @alpha\n */\nexport interface PromiseCacheOptions {\n\t/**\n\t * Common expiration policy for all items added to this cache\n\t */\n\texpiry?: PromiseCacheExpiry;\n\t/**\n\t * If the stored Promise is rejected with a particular error, should the given key be removed?\n\t */\n\t// TODO: Use `unknown` instead (API breaking)\n\t// eslint-disable-next-line @typescript-eslint/no-explicit-any\n\tremoveOnError?: (error: any) => boolean;\n}\n\n/**\n * Handles garbage collection of expiring cache entries.\n * Not exported.\n */\nclass GarbageCollector<TKey> {\n\tprivate readonly gcTimeouts = new Map<TKey, ReturnType<typeof setTimeout>>();\n\n\tpublic constructor(\n\t\tprivate readonly expiry: PromiseCacheExpiry,\n\t\tprivate readonly cleanup: (key: TKey) => void,\n\t) {}\n\n\t/**\n\t * Schedule GC for the given key, as applicable\n\t */\n\tpublic schedule(key: TKey): void {\n\t\tif (this.expiry.policy !== \"indefinite\") {\n\t\t\tthis.gcTimeouts.set(\n\t\t\t\tkey,\n\t\t\t\tsetTimeout(() => {\n\t\t\t\t\tthis.cleanup(key);\n\t\t\t\t\tthis.cancel(key);\n\t\t\t\t}, this.expiry.durationMs),\n\t\t\t);\n\t\t}\n\t}\n\n\t/**\n\t * Cancel any pending GC for the given key\n\t */\n\tpublic cancel(key: TKey): void {\n\t\tconst timeout = this.gcTimeouts.get(key);\n\t\tif (timeout !== undefined) {\n\t\t\tclearTimeout(timeout);\n\t\t\tthis.gcTimeouts.delete(key);\n\t\t}\n\t}\n\n\t/**\n\t * Update any pending GC for the given key, as applicable\n\t */\n\tpublic update(key: TKey): void {\n\t\t// Cancel/reschedule new GC if the policy is sliding\n\t\tif (this.expiry.policy === \"sliding\") {\n\t\t\tthis.cancel(key);\n\t\t\tthis.schedule(key);\n\t\t}\n\t}\n}\n\n/**\n * A specialized cache for async work, allowing you to safely cache the promised result of some async work\n * without fear of running it multiple times or losing track of errors.\n * @alpha\n */\nexport class PromiseCache<TKey, TResult> {\n\tprivate readonly cache = new Map<TKey, Promise<TResult>>();\n\tprivate readonly gc: GarbageCollector<TKey>;\n\n\tprivate readonly removeOnError: (error: unknown) => boolean;\n\n\t/**\n\t * Create the PromiseCache with the given options, with the following defaults:\n\t *\n\t * expiry: indefinite, removeOnError: true for all errors\n\t */\n\tpublic constructor({\n\t\texpiry = { policy: \"indefinite\" },\n\t\tremoveOnError = (): boolean => true,\n\t}: PromiseCacheOptions = {}) {\n\t\tthis.removeOnError = removeOnError;\n\t\tthis.gc = new GarbageCollector<TKey>(expiry, (key) => this.remove(key));\n\t}\n\n\t/**\n\t * Check if there's anything cached at the given key\n\t */\n\tpublic has(key: TKey): boolean {\n\t\treturn this.cache.has(key);\n\t}\n\n\t/**\n\t * Get the Promise for the given key, or undefined if it's not found.\n\t * Extend expiry if applicable.\n\t */\n\tpublic get(key: TKey): Promise<TResult> | undefined {\n\t\tif (this.has(key)) {\n\t\t\tthis.gc.update(key);\n\t\t}\n\t\treturn this.cache.get(key);\n\t}\n\n\t/**\n\t * Remove the Promise for the given key, returning true if it was found and removed\n\t */\n\tpublic remove(key: TKey): boolean {\n\t\tthis.gc.cancel(key);\n\t\treturn this.cache.delete(key);\n\t}\n\n\t/**\n\t * Try to add the result of the given asyncFn, without overwriting an existing cache entry at that key.\n\t * Returns a Promise for the added or existing async work being done at that key.\n\t * @param key - key name where to store the async work\n\t * @param asyncFn - the async work to do and store, if not already in progress under the given key\n\t */\n\tpublic async addOrGet(key: TKey, asyncFn: () => Promise<TResult>): Promise<TResult> {\n\t\t// NOTE: Do not await the Promise returned by asyncFn!\n\t\t// Let the caller do so once we return or after a subsequent call to get\n\t\tlet promise = this.get(key);\n\t\tif (promise === undefined) {\n\t\t\t// Wrap in an async lambda in case asyncFn disabled @typescript-eslint/promise-function-async\n\t\t\tconst safeAsyncFn = async (): Promise<TResult> => asyncFn();\n\n\t\t\t// Start the async work and put the Promise in the cache\n\t\t\tpromise = safeAsyncFn();\n\t\t\tthis.cache.set(key, promise);\n\n\t\t\t// If asyncFn throws, we may remove the Promise from the cache\n\t\t\tpromise.catch((error) => {\n\t\t\t\tif (this.removeOnError(error)) {\n\t\t\t\t\tthis.remove(key);\n\t\t\t\t}\n\t\t\t});\n\n\t\t\tthis.gc.schedule(key);\n\t\t}\n\n\t\treturn promise;\n\t}\n\n\t/**\n\t * Try to add the result of the given asyncFn, without overwriting an existing cache entry at that key.\n\t * Returns false if the cache already contained an entry at that key, and true otherwise.\n\t * @param key - key name where to store the async work\n\t * @param asyncFn - the async work to do and store, if not already in progress under the given key\n\t */\n\tpublic add(key: TKey, asyncFn: () => Promise<TResult>): boolean {\n\t\tconst alreadyPresent = this.has(key);\n\n\t\t// We are blindly adding the Promise to the cache here, which introduces a Promise in this scope.\n\t\t// Swallow Promise rejections here, since whoever gets this out of the cache to use it will await/catch.\n\t\tthis.addOrGet(key, asyncFn).catch(() => {});\n\n\t\treturn !alreadyPresent;\n\t}\n\n\t/**\n\t * Try to add the given value, without overwriting an existing cache entry at that key.\n\t * Returns a Promise for the added or existing async work being done at that key.\n\t * @param key - key name where to store the async work\n\t * @param value - value to store\n\t */\n\tpublic async addValueOrGet(key: TKey, value: TResult): Promise<TResult> {\n\t\treturn this.addOrGet(key, async () => value);\n\t}\n\n\t/**\n\t * Try to add the given value, without overwriting an existing cache entry at that key.\n\t * Returns false if the cache already contained an entry at that key, and true otherwise.\n\t * @param key - key name where to store the value\n\t * @param value - value to store\n\t */\n\tpublic addValue(key: TKey, value: TResult): boolean {\n\t\treturn this.add(key, async () => value);\n\t}\n}\n"]}
|
package/dist/promises.d.ts
CHANGED
package/dist/promises.js
CHANGED
package/dist/promises.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"promises.js","sourceRoot":"","sources":["../src/promises.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH;;;GAGG;AACH,MAAa,QAAQ;IAMpB;QAFQ,cAAS,GAAY,KAAK,CAAC;QAGlC,IAAI,CAAC,CAAC,GAAG,IAAI,OAAO,CAAI,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;YAC3C,IAAI,CAAC,GAAG,GAAG,OAAO,CAAC;YACnB,IAAI,CAAC,GAAG,GAAG,MAAM,CAAC;QACnB,CAAC,CAAC,CAAC;IACJ,CAAC;IACD;;OAEG;IACH,IAAW,WAAW;QACrB,OAAO,IAAI,CAAC,SAAS,CAAC;IACvB,CAAC;IAED;;;;OAIG;IACH,IAAW,OAAO;QACjB,OAAO,IAAI,CAAC,CAAC,CAAC;IACf,CAAC;IAED;;;;OAIG;IACI,OAAO,CAAC,KAAyB;QACvC,IAAI,IAAI,CAAC,GAAG,KAAK,SAAS,EAAE;YAC3B,IAAI,CAAC,SAAS,GAAG,IAAI,CAAC;YACtB,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;SAChB;IACF,CAAC;IAED;;;;OAIG;IACH,6CAA6C;IAC7C,iHAAiH;IAC1G,MAAM,CAAC,KAAU;QACvB,IAAI,IAAI,CAAC,GAAG,KAAK,SAAS,EAAE;YAC3B,IAAI,CAAC,SAAS,GAAG,IAAI,CAAC;YACtB,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;SAChB;IACF,CAAC;CACD;AArDD,4BAqDC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\n/**\n * A deferred creates a promise and the ability to resolve or reject it\n * @
|
|
1
|
+
{"version":3,"file":"promises.js","sourceRoot":"","sources":["../src/promises.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH;;;GAGG;AACH,MAAa,QAAQ;IAMpB;QAFQ,cAAS,GAAY,KAAK,CAAC;QAGlC,IAAI,CAAC,CAAC,GAAG,IAAI,OAAO,CAAI,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;YAC3C,IAAI,CAAC,GAAG,GAAG,OAAO,CAAC;YACnB,IAAI,CAAC,GAAG,GAAG,MAAM,CAAC;QACnB,CAAC,CAAC,CAAC;IACJ,CAAC;IACD;;OAEG;IACH,IAAW,WAAW;QACrB,OAAO,IAAI,CAAC,SAAS,CAAC;IACvB,CAAC;IAED;;;;OAIG;IACH,IAAW,OAAO;QACjB,OAAO,IAAI,CAAC,CAAC,CAAC;IACf,CAAC;IAED;;;;OAIG;IACI,OAAO,CAAC,KAAyB;QACvC,IAAI,IAAI,CAAC,GAAG,KAAK,SAAS,EAAE;YAC3B,IAAI,CAAC,SAAS,GAAG,IAAI,CAAC;YACtB,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;SAChB;IACF,CAAC;IAED;;;;OAIG;IACH,6CAA6C;IAC7C,iHAAiH;IAC1G,MAAM,CAAC,KAAU;QACvB,IAAI,IAAI,CAAC,GAAG,KAAK,SAAS,EAAE;YAC3B,IAAI,CAAC,SAAS,GAAG,IAAI,CAAC;YACtB,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;SAChB;IACF,CAAC;CACD;AArDD,4BAqDC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\n/**\n * A deferred creates a promise and the ability to resolve or reject it\n * @alpha\n */\nexport class Deferred<T> {\n\tprivate readonly p: Promise<T>;\n\tprivate res: ((value: T | PromiseLike<T>) => void) | undefined;\n\tprivate rej: ((reason?: unknown) => void) | undefined;\n\tprivate completed: boolean = false;\n\n\tpublic constructor() {\n\t\tthis.p = new Promise<T>((resolve, reject) => {\n\t\t\tthis.res = resolve;\n\t\t\tthis.rej = reject;\n\t\t});\n\t}\n\t/**\n\t * Returns whether the underlying promise has been completed\n\t */\n\tpublic get isCompleted(): boolean {\n\t\treturn this.completed;\n\t}\n\n\t/**\n\t * Retrieves the underlying promise for the deferred\n\t *\n\t * @returns the underlying promise\n\t */\n\tpublic get promise(): Promise<T> {\n\t\treturn this.p;\n\t}\n\n\t/**\n\t * Resolves the promise\n\t *\n\t * @param value - the value to resolve the promise with\n\t */\n\tpublic resolve(value: T | PromiseLike<T>): void {\n\t\tif (this.res !== undefined) {\n\t\t\tthis.completed = true;\n\t\t\tthis.res(value);\n\t\t}\n\t}\n\n\t/**\n\t * Rejects the promise\n\t *\n\t * @param value - the value to reject the promise with\n\t */\n\t// TODO: Use `unknown` instead (API breaking)\n\t// eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/explicit-module-boundary-types\n\tpublic reject(error: any): void {\n\t\tif (this.rej !== undefined) {\n\t\t\tthis.completed = true;\n\t\t\tthis.rej(error);\n\t\t}\n\t}\n}\n"]}
|
package/lib/assert.js
CHANGED
|
@@ -1,7 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
1
2
|
/*!
|
|
2
3
|
* Copyright (c) Microsoft Corporation and contributors. All rights reserved.
|
|
3
4
|
* Licensed under the MIT License.
|
|
4
5
|
*/
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
exports.assert = void 0;
|
|
5
8
|
/**
|
|
6
9
|
* A browser friendly assert library.
|
|
7
10
|
* Use this instead of the 'assert' package, which has a big impact on bundle sizes.
|
|
@@ -13,9 +16,10 @@
|
|
|
13
16
|
* use numbered error codes instead.
|
|
14
17
|
* @internal
|
|
15
18
|
*/
|
|
16
|
-
|
|
19
|
+
function assert(condition, message) {
|
|
17
20
|
if (!condition) {
|
|
18
21
|
throw new Error(typeof message === "number" ? `0x${message.toString(16).padStart(3, "0")}` : message);
|
|
19
22
|
}
|
|
20
23
|
}
|
|
24
|
+
exports.assert = assert;
|
|
21
25
|
//# sourceMappingURL=assert.js.map
|
package/lib/assert.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"assert.js","sourceRoot":"","sources":["../src/assert.ts"],"names":[],"mappings":"AAAA;;;GAGG
|
|
1
|
+
{"version":3,"file":"assert.js","sourceRoot":"","sources":["../src/assert.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH;;;;;;;;;;GAUG;AACH,SAAgB,MAAM,CAAC,SAAkB,EAAE,OAAwB;IAClE,IAAI,CAAC,SAAS,EAAE;QACf,MAAM,IAAI,KAAK,CACd,OAAO,OAAO,KAAK,QAAQ,CAAC,CAAC,CAAC,KAAK,OAAO,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,QAAQ,CAAC,CAAC,EAAE,GAAG,CAAC,EAAE,CAAC,CAAC,CAAC,OAAO,CACpF,CAAC;KACF;AACF,CAAC;AAND,wBAMC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\n/**\n * A browser friendly assert library.\n * Use this instead of the 'assert' package, which has a big impact on bundle sizes.\n * @param condition - The condition that should be true, if the condition is false an error will be thrown.\n * Only use this API when `false` indicates a logic error in the problem and thus a bug that should be fixed.\n * @param message - The message to include in the error when the condition does not hold.\n * A number should not be specified manually: use a string.\n * Before a release, policy-check should be run, which will convert any asserts still using strings to\n * use numbered error codes instead.\n * @internal\n */\nexport function assert(condition: boolean, message: string | number): asserts condition {\n\tif (!condition) {\n\t\tthrow new Error(\n\t\t\ttypeof message === \"number\" ? `0x${message.toString(16).padStart(3, \"0\")}` : message,\n\t\t);\n\t}\n}\n"]}
|
package/lib/compare.js
CHANGED
|
@@ -1,7 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
1
2
|
/*!
|
|
2
3
|
* Copyright (c) Microsoft Corporation and contributors. All rights reserved.
|
|
3
4
|
* Licensed under the MIT License.
|
|
4
5
|
*/
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
exports.compareArrays = void 0;
|
|
5
8
|
/**
|
|
6
9
|
* Compare two arrays. Returns true if their elements are equivalent and in the same order.
|
|
7
10
|
*
|
|
@@ -12,7 +15,7 @@
|
|
|
12
15
|
* @param comparator - The function used to check if two `T`s are equivalent.
|
|
13
16
|
* Defaults to `Object.is()` equality (a shallow compare where NaN = NaN and -0 ≠ 0)
|
|
14
17
|
*/
|
|
15
|
-
|
|
18
|
+
const compareArrays = (left, right, comparator = (leftItem, rightItem) => Object.is(leftItem, rightItem)) => {
|
|
16
19
|
// PERF: 'for-loop' and 'Array.every()' tied.
|
|
17
20
|
// '===' and 'Object.is()' tied.
|
|
18
21
|
// Trivial acceptance adds no measurable overhead.
|
|
@@ -21,4 +24,5 @@ export const compareArrays = (left, right, comparator = (leftItem, rightItem) =>
|
|
|
21
24
|
(left.length === right.length && // Trivial rejection: 'left' and 'right' are different lengths
|
|
22
25
|
left.every((leftItem, index) => comparator(leftItem, right[index], index))));
|
|
23
26
|
};
|
|
27
|
+
exports.compareArrays = compareArrays;
|
|
24
28
|
//# sourceMappingURL=compare.js.map
|
package/lib/compare.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"compare.js","sourceRoot":"","sources":["../src/compare.ts"],"names":[],"mappings":"AAAA;;;GAGG
|
|
1
|
+
{"version":3,"file":"compare.js","sourceRoot":"","sources":["../src/compare.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH;;;;;;;;;GASG;AACI,MAAM,aAAa,GAAG,CAC5B,IAAkB,EAClB,KAAmB,EACnB,aAAoE,CACnE,QAAW,EACX,SAAY,EACF,EAAE,CAAC,MAAM,CAAC,EAAE,CAAC,QAAQ,EAAE,SAAS,CAAC,EAClC,EAAE;IACZ,6CAA6C;IAC7C,sCAAsC;IACtC,wDAAwD;IACxD,sEAAsE;IACtE,OAAO,CACN,IAAI,KAAK,KAAK,IAAI,+DAA+D;QACjF,CAAC,IAAI,CAAC,MAAM,KAAK,KAAK,CAAC,MAAM,IAAI,8DAA8D;YAC9F,IAAI,CAAC,KAAK,CAAC,CAAC,QAAQ,EAAE,KAAK,EAAE,EAAE,CAAC,UAAU,CAAC,QAAQ,EAAE,KAAK,CAAC,KAAK,CAAC,EAAE,KAAK,CAAC,CAAC,CAAC,CAC5E,CAAC;AACH,CAAC,CAAC;AAjBW,QAAA,aAAa,iBAiBxB","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\n/**\n * Compare two arrays. Returns true if their elements are equivalent and in the same order.\n *\n * @internal\n *\n * @param left - The first array to compare\n * @param right - The second array to compare\n * @param comparator - The function used to check if two `T`s are equivalent.\n * Defaults to `Object.is()` equality (a shallow compare where NaN = NaN and -0 ≠ 0)\n */\nexport const compareArrays = <T>(\n\tleft: readonly T[],\n\tright: readonly T[],\n\tcomparator: (leftItem: T, rightItem: T, index: number) => boolean = (\n\t\tleftItem: T,\n\t\trightItem: T,\n\t): boolean => Object.is(leftItem, rightItem),\n): boolean => {\n\t// PERF: 'for-loop' and 'Array.every()' tied.\n\t// '===' and 'Object.is()' tied.\n\t// Trivial acceptance adds no measurable overhead.\n\t// 30% penalty vs. baseline for exported function [node 14 x64].\n\treturn (\n\t\tleft === right || // Trivial acceptance: 'left' and 'right' are the same instance\n\t\t(left.length === right.length && // Trivial rejection: 'left' and 'right' are different lengths\n\t\t\tleft.every((leftItem, index) => comparator(leftItem, right[index], index)))\n\t);\n};\n"]}
|
|
@@ -2,7 +2,39 @@
|
|
|
2
2
|
|
|
3
3
|
/* Excluded from this release type: compareArrays */
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
/**
|
|
6
|
+
* A deferred creates a promise and the ability to resolve or reject it
|
|
7
|
+
* @alpha
|
|
8
|
+
*/
|
|
9
|
+
export declare class Deferred<T> {
|
|
10
|
+
private readonly p;
|
|
11
|
+
private res;
|
|
12
|
+
private rej;
|
|
13
|
+
private completed;
|
|
14
|
+
constructor();
|
|
15
|
+
/**
|
|
16
|
+
* Returns whether the underlying promise has been completed
|
|
17
|
+
*/
|
|
18
|
+
get isCompleted(): boolean;
|
|
19
|
+
/**
|
|
20
|
+
* Retrieves the underlying promise for the deferred
|
|
21
|
+
*
|
|
22
|
+
* @returns the underlying promise
|
|
23
|
+
*/
|
|
24
|
+
get promise(): Promise<T>;
|
|
25
|
+
/**
|
|
26
|
+
* Resolves the promise
|
|
27
|
+
*
|
|
28
|
+
* @param value - the value to resolve the promise with
|
|
29
|
+
*/
|
|
30
|
+
resolve(value: T | PromiseLike<T>): void;
|
|
31
|
+
/**
|
|
32
|
+
* Rejects the promise
|
|
33
|
+
*
|
|
34
|
+
* @param value - the value to reject the promise with
|
|
35
|
+
*/
|
|
36
|
+
reject(error: any): void;
|
|
37
|
+
}
|
|
6
38
|
|
|
7
39
|
/* Excluded from this release type: delay */
|
|
8
40
|
|
|
@@ -24,11 +56,92 @@
|
|
|
24
56
|
|
|
25
57
|
/* Excluded from this release type: NumberComparer */
|
|
26
58
|
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
59
|
+
/**
|
|
60
|
+
* A specialized cache for async work, allowing you to safely cache the promised result of some async work
|
|
61
|
+
* without fear of running it multiple times or losing track of errors.
|
|
62
|
+
* @alpha
|
|
63
|
+
*/
|
|
64
|
+
export declare class PromiseCache<TKey, TResult> {
|
|
65
|
+
private readonly cache;
|
|
66
|
+
private readonly gc;
|
|
67
|
+
private readonly removeOnError;
|
|
68
|
+
/**
|
|
69
|
+
* Create the PromiseCache with the given options, with the following defaults:
|
|
70
|
+
*
|
|
71
|
+
* expiry: indefinite, removeOnError: true for all errors
|
|
72
|
+
*/
|
|
73
|
+
constructor({ expiry, removeOnError, }?: PromiseCacheOptions);
|
|
74
|
+
/**
|
|
75
|
+
* Check if there's anything cached at the given key
|
|
76
|
+
*/
|
|
77
|
+
has(key: TKey): boolean;
|
|
78
|
+
/**
|
|
79
|
+
* Get the Promise for the given key, or undefined if it's not found.
|
|
80
|
+
* Extend expiry if applicable.
|
|
81
|
+
*/
|
|
82
|
+
get(key: TKey): Promise<TResult> | undefined;
|
|
83
|
+
/**
|
|
84
|
+
* Remove the Promise for the given key, returning true if it was found and removed
|
|
85
|
+
*/
|
|
86
|
+
remove(key: TKey): boolean;
|
|
87
|
+
/**
|
|
88
|
+
* Try to add the result of the given asyncFn, without overwriting an existing cache entry at that key.
|
|
89
|
+
* Returns a Promise for the added or existing async work being done at that key.
|
|
90
|
+
* @param key - key name where to store the async work
|
|
91
|
+
* @param asyncFn - the async work to do and store, if not already in progress under the given key
|
|
92
|
+
*/
|
|
93
|
+
addOrGet(key: TKey, asyncFn: () => Promise<TResult>): Promise<TResult>;
|
|
94
|
+
/**
|
|
95
|
+
* Try to add the result of the given asyncFn, without overwriting an existing cache entry at that key.
|
|
96
|
+
* Returns false if the cache already contained an entry at that key, and true otherwise.
|
|
97
|
+
* @param key - key name where to store the async work
|
|
98
|
+
* @param asyncFn - the async work to do and store, if not already in progress under the given key
|
|
99
|
+
*/
|
|
100
|
+
add(key: TKey, asyncFn: () => Promise<TResult>): boolean;
|
|
101
|
+
/**
|
|
102
|
+
* Try to add the given value, without overwriting an existing cache entry at that key.
|
|
103
|
+
* Returns a Promise for the added or existing async work being done at that key.
|
|
104
|
+
* @param key - key name where to store the async work
|
|
105
|
+
* @param value - value to store
|
|
106
|
+
*/
|
|
107
|
+
addValueOrGet(key: TKey, value: TResult): Promise<TResult>;
|
|
108
|
+
/**
|
|
109
|
+
* Try to add the given value, without overwriting an existing cache entry at that key.
|
|
110
|
+
* Returns false if the cache already contained an entry at that key, and true otherwise.
|
|
111
|
+
* @param key - key name where to store the value
|
|
112
|
+
* @param value - value to store
|
|
113
|
+
*/
|
|
114
|
+
addValue(key: TKey, value: TResult): boolean;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
/**
|
|
118
|
+
* Three supported expiry policies:
|
|
119
|
+
* - indefinite: entries don't expire and must be explicitly removed
|
|
120
|
+
* - absolute: entries expire after the given duration in MS, even if accessed multiple times in the mean time
|
|
121
|
+
* - sliding: entries expire after the given duration in MS of inactivity (i.e. get resets the clock)
|
|
122
|
+
* @alpha
|
|
123
|
+
*/
|
|
124
|
+
export declare type PromiseCacheExpiry = {
|
|
125
|
+
policy: "indefinite";
|
|
126
|
+
} | {
|
|
127
|
+
policy: "absolute" | "sliding";
|
|
128
|
+
durationMs: number;
|
|
129
|
+
};
|
|
130
|
+
|
|
131
|
+
/**
|
|
132
|
+
* Options for configuring the {@link PromiseCache}
|
|
133
|
+
* @alpha
|
|
134
|
+
*/
|
|
135
|
+
export declare interface PromiseCacheOptions {
|
|
136
|
+
/**
|
|
137
|
+
* Common expiration policy for all items added to this cache
|
|
138
|
+
*/
|
|
139
|
+
expiry?: PromiseCacheExpiry;
|
|
140
|
+
/**
|
|
141
|
+
* If the stored Promise is rejected with a particular error, should the given key be removed?
|
|
142
|
+
*/
|
|
143
|
+
removeOnError?: (error: any) => boolean;
|
|
144
|
+
}
|
|
32
145
|
|
|
33
146
|
/* Excluded from this release type: PromiseTimer */
|
|
34
147
|
|
|
@@ -25,7 +25,7 @@ export declare const compareArrays: <T>(left: readonly T[], right: readonly T[],
|
|
|
25
25
|
|
|
26
26
|
/**
|
|
27
27
|
* A deferred creates a promise and the ability to resolve or reject it
|
|
28
|
-
* @
|
|
28
|
+
* @alpha
|
|
29
29
|
*/
|
|
30
30
|
export declare class Deferred<T> {
|
|
31
31
|
private readonly p;
|
|
@@ -231,7 +231,7 @@ export declare const NumberComparer: IComparer<number>;
|
|
|
231
231
|
/**
|
|
232
232
|
* A specialized cache for async work, allowing you to safely cache the promised result of some async work
|
|
233
233
|
* without fear of running it multiple times or losing track of errors.
|
|
234
|
-
* @
|
|
234
|
+
* @alpha
|
|
235
235
|
*/
|
|
236
236
|
export declare class PromiseCache<TKey, TResult> {
|
|
237
237
|
private readonly cache;
|
|
@@ -291,7 +291,7 @@ export declare class PromiseCache<TKey, TResult> {
|
|
|
291
291
|
* - indefinite: entries don't expire and must be explicitly removed
|
|
292
292
|
* - absolute: entries expire after the given duration in MS, even if accessed multiple times in the mean time
|
|
293
293
|
* - sliding: entries expire after the given duration in MS of inactivity (i.e. get resets the clock)
|
|
294
|
-
* @
|
|
294
|
+
* @alpha
|
|
295
295
|
*/
|
|
296
296
|
export declare type PromiseCacheExpiry = {
|
|
297
297
|
policy: "indefinite";
|
|
@@ -302,7 +302,7 @@ export declare type PromiseCacheExpiry = {
|
|
|
302
302
|
|
|
303
303
|
/**
|
|
304
304
|
* Options for configuring the {@link PromiseCache}
|
|
305
|
-
* @
|
|
305
|
+
* @alpha
|
|
306
306
|
*/
|
|
307
307
|
export declare interface PromiseCacheOptions {
|
|
308
308
|
/**
|
package/lib/delay.js
CHANGED
|
@@ -1,11 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
1
2
|
/*!
|
|
2
3
|
* Copyright (c) Microsoft Corporation and contributors. All rights reserved.
|
|
3
4
|
* Licensed under the MIT License.
|
|
4
5
|
*/
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
exports.delay = void 0;
|
|
5
8
|
/**
|
|
6
9
|
* Returns a promise that resolves after `timeMs`.
|
|
7
10
|
* @param timeMs - Time in milliseconds to wait.
|
|
8
11
|
* @internal
|
|
9
12
|
*/
|
|
10
|
-
|
|
13
|
+
const delay = async (timeMs) => new Promise((resolve) => setTimeout(() => resolve(), timeMs));
|
|
14
|
+
exports.delay = delay;
|
|
11
15
|
//# sourceMappingURL=delay.js.map
|
package/lib/delay.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"delay.js","sourceRoot":"","sources":["../src/delay.ts"],"names":[],"mappings":"AAAA;;;GAGG
|
|
1
|
+
{"version":3,"file":"delay.js","sourceRoot":"","sources":["../src/delay.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH;;;;GAIG;AACI,MAAM,KAAK,GAAG,KAAK,EAAE,MAAc,EAAiB,EAAE,CAC5D,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,UAAU,CAAC,GAAG,EAAE,CAAC,OAAO,EAAE,EAAE,MAAM,CAAC,CAAC,CAAC;AADlD,QAAA,KAAK,SAC6C","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\n/**\n * Returns a promise that resolves after `timeMs`.\n * @param timeMs - Time in milliseconds to wait.\n * @internal\n */\nexport const delay = async (timeMs: number): Promise<void> =>\n\tnew Promise((resolve) => setTimeout(() => resolve(), timeMs));\n"]}
|
package/lib/heap.js
CHANGED
|
@@ -1,12 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
1
2
|
/*!
|
|
2
3
|
* Copyright (c) Microsoft Corporation and contributors. All rights reserved.
|
|
3
4
|
* Licensed under the MIT License.
|
|
4
5
|
*/
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
exports.Heap = exports.NumberComparer = void 0;
|
|
5
8
|
/**
|
|
6
9
|
* A comparer for numbers.
|
|
7
10
|
* @internal
|
|
8
11
|
*/
|
|
9
|
-
|
|
12
|
+
exports.NumberComparer = {
|
|
10
13
|
/**
|
|
11
14
|
* The compare function for numbers.
|
|
12
15
|
* @returns The difference of the two numbers.
|
|
@@ -21,7 +24,7 @@ export const NumberComparer = {
|
|
|
21
24
|
* Ordered {@link https://en.wikipedia.org/wiki/Heap_(data_structure) | Heap} data structure implementation.
|
|
22
25
|
* @internal
|
|
23
26
|
*/
|
|
24
|
-
|
|
27
|
+
class Heap {
|
|
25
28
|
/**
|
|
26
29
|
* Creates an instance of `Heap` with comparer.
|
|
27
30
|
* @param comp - A comparer that specify how elements are ordered.
|
|
@@ -134,4 +137,5 @@ export class Heap {
|
|
|
134
137
|
this.L[j].position = j;
|
|
135
138
|
}
|
|
136
139
|
}
|
|
140
|
+
exports.Heap = Heap;
|
|
137
141
|
//# sourceMappingURL=heap.js.map
|
package/lib/heap.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"heap.js","sourceRoot":"","sources":["../src/heap.ts"],"names":[],"mappings":"AAAA;;;GAGG
|
|
1
|
+
{"version":3,"file":"heap.js","sourceRoot":"","sources":["../src/heap.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAoBH;;;GAGG;AACU,QAAA,cAAc,GAAsB;IAChD;;;OAGG;IACH,OAAO,EAAE,CAAC,CAAC,EAAE,CAAC,EAAU,EAAE,CAAC,CAAC,GAAG,CAAC;IAEhC;;OAEG;IACH,GAAG,EAAE,MAAM,CAAC,SAAS;CACrB,CAAC;AAWF;;;GAGG;AACH,MAAa,IAAI;IAGhB;;;OAGG;IACH,YAAmB,IAAkB;QAAlB,SAAI,GAAJ,IAAI,CAAc;QACpC,IAAI,CAAC,CAAC,GAAG,CAAC,EAAE,KAAK,EAAE,IAAI,CAAC,GAAG,EAAE,QAAQ,EAAE,CAAC,EAAE,CAAC,CAAC;IAC7C,CAAC;IAED;;;;OAIG;IACI,IAAI;QACV,OAAO,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;IAClB,CAAC;IAED;;;;OAIG;IACI,GAAG;QACT,IAAI,CAAC,IAAI,CAAC,CAAC,EAAE,IAAI,CAAC,KAAK,EAAE,CAAC,CAAC;QAC3B,MAAM,CAAC,GAAG,IAAI,CAAC,CAAC,CAAC,GAAG,EAAE,CAAC;QACvB,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC;QAChB,oEAAoE;QACpE,OAAO,CAAE,CAAC,KAAK,CAAC;IACjB,CAAC;IAED;;;;;O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AS;QAChC,MAAM,GAAG,GAAG,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;QACtB,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;QACtB,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,QAAQ,GAAG,CAAC,CAAC;QACvB,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,GAAG,CAAC;QAChB,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,QAAQ,GAAG,CAAC,CAAC;IACxB,CAAC;CACD;AA5HD,oBA4HC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\n/**\n * Interface for a comparer.\n * @internal\n */\nexport interface IComparer<T> {\n\t/**\n\t * The minimum value of type T.\n\t */\n\tmin: T;\n\n\t/**\n\t * Compare the two value\n\t *\n\t * @returns 0 if the value is equal, negative number if a is smaller then b, positive number otherwise\n\t */\n\tcompare(a: T, b: T): number;\n}\n\n/**\n * A comparer for numbers.\n * @internal\n */\nexport const NumberComparer: IComparer<number> = {\n\t/**\n\t * The compare function for numbers.\n\t * @returns The difference of the two numbers.\n\t */\n\tcompare: (a, b): number => a - b,\n\n\t/**\n\t * The minimum value of a JavaScript number, which is `Number.MIN_VALUE`.\n\t */\n\tmin: Number.MIN_VALUE,\n};\n\n/**\n * Interface to a node in {@link Heap}.\n * @internal\n */\nexport interface IHeapNode<T> {\n\tvalue: T;\n\tposition: number;\n}\n\n/**\n * Ordered {@link https://en.wikipedia.org/wiki/Heap_(data_structure) | Heap} data structure implementation.\n * @internal\n */\nexport class Heap<T> {\n\tprivate L: IHeapNode<T>[];\n\n\t/**\n\t * Creates an instance of `Heap` with comparer.\n\t * @param comp - A comparer that specify how elements are ordered.\n\t */\n\tconstructor(public comp: IComparer<T>) {\n\t\tthis.L = [{ value: comp.min, position: 0 }];\n\t}\n\n\t/**\n\t * Return the smallest element in the heap as determined by the order of the comparer\n\t *\n\t * @returns Heap node containing the smallest element\n\t */\n\tpublic peek(): IHeapNode<T> {\n\t\treturn this.L[1];\n\t}\n\n\t/**\n\t * Get and remove the smallest element in the heap as determined by the order of the comparer\n\t *\n\t * @returns The smallest value in the heap\n\t */\n\tpublic get(): T {\n\t\tthis.swap(1, this.count());\n\t\tconst x = this.L.pop();\n\t\tthis.fixdown(1);\n\t\t// eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n\t\treturn x!.value;\n\t}\n\n\t/**\n\t * Add a value to the heap\n\t *\n\t * @param x - value to add\n\t * @returns The heap node that contains the value\n\t */\n\tpublic add(x: T): IHeapNode<T> {\n\t\tconst node = { value: x, position: this.L.length };\n\t\tthis.L.push(node);\n\t\tthis.fixup(this.count());\n\n\t\treturn node;\n\t}\n\n\t/**\n\t * Allows for the Heap to be updated after a node's value changes.\n\t */\n\tpublic update(node: IHeapNode<T>): void {\n\t\tconst k = node.position;\n\t\tif (this.isGreaterThanParent(k)) {\n\t\t\tthis.fixup(k);\n\t\t} else {\n\t\t\tthis.fixdown(k);\n\t\t}\n\t}\n\n\t/**\n\t * Removes the given node from the heap.\n\t *\n\t * @param node - The node to remove from the heap.\n\t */\n\tpublic remove(node: IHeapNode<T>): void {\n\t\t// Move the node we want to remove to the end of the array\n\t\tconst position = node.position;\n\t\tthis.swap(node.position, this.L.length - 1);\n\t\tthis.L.splice(-1);\n\n\t\t// Update the swapped node assuming we didn't remove the end of the list\n\t\tif (position !== this.L.length) {\n\t\t\tthis.update(this.L[position]);\n\t\t}\n\t}\n\n\t/**\n\t * Get the number of elements in the Heap.\n\t *\n\t * @returns The number of elements in the Heap.\n\t */\n\tpublic count(): number {\n\t\treturn this.L.length - 1;\n\t}\n\n\tprivate fixup(pos: number): void {\n\t\tlet k = pos;\n\t\twhile (this.isGreaterThanParent(k)) {\n\t\t\t// eslint-disable-next-line no-bitwise\n\t\t\tconst parent = k >> 1;\n\t\t\tthis.swap(k, parent);\n\t\t\tk = parent;\n\t\t}\n\t}\n\n\tprivate isGreaterThanParent(k: number): boolean {\n\t\t// eslint-disable-next-line no-bitwise\n\t\treturn k > 1 && this.comp.compare(this.L[k >> 1].value, this.L[k].value) > 0;\n\t}\n\n\tprivate fixdown(pos: number): void {\n\t\tlet k = pos;\n\t\t// eslint-disable-next-line no-bitwise\n\t\twhile (k << 1 <= this.count()) {\n\t\t\t// eslint-disable-next-line no-bitwise\n\t\t\tlet j = k << 1;\n\t\t\tif (j < this.count() && this.comp.compare(this.L[j].value, this.L[j + 1].value) > 0) {\n\t\t\t\tj++;\n\t\t\t}\n\t\t\tif (this.comp.compare(this.L[k].value, this.L[j].value) <= 0) {\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tthis.swap(k, j);\n\t\t\tk = j;\n\t\t}\n\t}\n\n\tprivate swap(k: number, j: number): void {\n\t\tconst tmp = this.L[k];\n\t\tthis.L[k] = this.L[j];\n\t\tthis.L[k].position = k;\n\t\tthis.L[j] = tmp;\n\t\tthis.L[j].position = j;\n\t}\n}\n"]}
|
package/lib/index.js
CHANGED
|
@@ -1,14 +1,30 @@
|
|
|
1
|
+
"use strict";
|
|
1
2
|
/*!
|
|
2
3
|
* Copyright (c) Microsoft Corporation and contributors. All rights reserved.
|
|
3
4
|
* Licensed under the MIT License.
|
|
4
5
|
*/
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
exports.unreachableCase = exports.Timer = exports.setLongTimeout = exports.PromiseTimer = exports.Deferred = exports.PromiseCache = exports.LazyPromise = exports.Lazy = exports.NumberComparer = exports.Heap = exports.delay = exports.compareArrays = exports.assert = void 0;
|
|
8
|
+
var assert_1 = require("./assert");
|
|
9
|
+
Object.defineProperty(exports, "assert", { enumerable: true, get: function () { return assert_1.assert; } });
|
|
10
|
+
var compare_1 = require("./compare");
|
|
11
|
+
Object.defineProperty(exports, "compareArrays", { enumerable: true, get: function () { return compare_1.compareArrays; } });
|
|
12
|
+
var delay_1 = require("./delay");
|
|
13
|
+
Object.defineProperty(exports, "delay", { enumerable: true, get: function () { return delay_1.delay; } });
|
|
14
|
+
var heap_1 = require("./heap");
|
|
15
|
+
Object.defineProperty(exports, "Heap", { enumerable: true, get: function () { return heap_1.Heap; } });
|
|
16
|
+
Object.defineProperty(exports, "NumberComparer", { enumerable: true, get: function () { return heap_1.NumberComparer; } });
|
|
17
|
+
var lazy_1 = require("./lazy");
|
|
18
|
+
Object.defineProperty(exports, "Lazy", { enumerable: true, get: function () { return lazy_1.Lazy; } });
|
|
19
|
+
Object.defineProperty(exports, "LazyPromise", { enumerable: true, get: function () { return lazy_1.LazyPromise; } });
|
|
20
|
+
var promiseCache_1 = require("./promiseCache");
|
|
21
|
+
Object.defineProperty(exports, "PromiseCache", { enumerable: true, get: function () { return promiseCache_1.PromiseCache; } });
|
|
22
|
+
var promises_1 = require("./promises");
|
|
23
|
+
Object.defineProperty(exports, "Deferred", { enumerable: true, get: function () { return promises_1.Deferred; } });
|
|
24
|
+
var timer_1 = require("./timer");
|
|
25
|
+
Object.defineProperty(exports, "PromiseTimer", { enumerable: true, get: function () { return timer_1.PromiseTimer; } });
|
|
26
|
+
Object.defineProperty(exports, "setLongTimeout", { enumerable: true, get: function () { return timer_1.setLongTimeout; } });
|
|
27
|
+
Object.defineProperty(exports, "Timer", { enumerable: true, get: function () { return timer_1.Timer; } });
|
|
28
|
+
var unreachable_1 = require("./unreachable");
|
|
29
|
+
Object.defineProperty(exports, "unreachableCase", { enumerable: true, get: function () { return unreachable_1.unreachableCase; } });
|
|
14
30
|
//# sourceMappingURL=index.js.map
|
package/lib/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;GAGG
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH,mCAAkC;AAAzB,gGAAA,MAAM,OAAA;AACf,qCAA0C;AAAjC,wGAAA,aAAa,OAAA;AACtB,iCAAgC;AAAvB,8FAAA,KAAK,OAAA;AACd,+BAAoE;AAA3D,4FAAA,IAAI,OAAA;AAAwB,sGAAA,cAAc,OAAA;AACnD,+BAA2C;AAAlC,4FAAA,IAAI,OAAA;AAAE,mGAAA,WAAW,OAAA;AAC1B,+CAAuF;AAA9E,4GAAA,YAAY,OAAA;AACrB,uCAAsC;AAA7B,oGAAA,QAAQ,OAAA;AACjB,iCAOiB;AAHhB,qGAAA,YAAY,OAAA;AACZ,uGAAA,cAAc,OAAA;AACd,8FAAA,KAAK,OAAA;AAEN,6CAAgD;AAAvC,8GAAA,eAAe,OAAA","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nexport { assert } from \"./assert\";\nexport { compareArrays } from \"./compare\";\nexport { delay } from \"./delay\";\nexport { Heap, IComparer, IHeapNode, NumberComparer } from \"./heap\";\nexport { Lazy, LazyPromise } from \"./lazy\";\nexport { PromiseCache, PromiseCacheExpiry, PromiseCacheOptions } from \"./promiseCache\";\nexport { Deferred } from \"./promises\";\nexport {\n\tIPromiseTimer,\n\tIPromiseTimerResult,\n\tITimer,\n\tPromiseTimer,\n\tsetLongTimeout,\n\tTimer,\n} from \"./timer\";\nexport { unreachableCase } from \"./unreachable\";\n"]}
|
package/lib/lazy.js
CHANGED
|
@@ -1,12 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
1
2
|
/*!
|
|
2
3
|
* Copyright (c) Microsoft Corporation and contributors. All rights reserved.
|
|
3
4
|
* Licensed under the MIT License.
|
|
4
5
|
*/
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
exports.LazyPromise = exports.Lazy = void 0;
|
|
5
8
|
/**
|
|
6
9
|
* Helper class for lazy initialized values. Ensures the value is only generated once, and remain immutable.
|
|
7
10
|
* @internal
|
|
8
11
|
*/
|
|
9
|
-
|
|
12
|
+
class Lazy {
|
|
10
13
|
/**
|
|
11
14
|
* Instantiates an instance of Lazy<T>.
|
|
12
15
|
* @param valueGenerator - The function that will generate the value when value is accessed the first time.
|
|
@@ -33,6 +36,7 @@ export class Lazy {
|
|
|
33
36
|
return this._value;
|
|
34
37
|
}
|
|
35
38
|
}
|
|
39
|
+
exports.Lazy = Lazy;
|
|
36
40
|
/**
|
|
37
41
|
* A lazy evaluated promise. The execute function is delayed until
|
|
38
42
|
* the promise is used, e.g. await, then, catch ...
|
|
@@ -40,7 +44,7 @@ export class Lazy {
|
|
|
40
44
|
* All calls are then proxied to the promise returned by the execute method.
|
|
41
45
|
* @internal
|
|
42
46
|
*/
|
|
43
|
-
|
|
47
|
+
class LazyPromise {
|
|
44
48
|
get [Symbol.toStringTag]() {
|
|
45
49
|
return this.getPromise()[Symbol.toStringTag];
|
|
46
50
|
}
|
|
@@ -76,4 +80,5 @@ export class LazyPromise {
|
|
|
76
80
|
return this.result;
|
|
77
81
|
}
|
|
78
82
|
}
|
|
83
|
+
exports.LazyPromise = LazyPromise;
|
|
79
84
|
//# sourceMappingURL=lazy.js.map
|
package/lib/lazy.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"lazy.js","sourceRoot":"","sources":["../src/lazy.ts"],"names":[],"mappings":"AAAA;;;GAGG
|
|
1
|
+
{"version":3,"file":"lazy.js","sourceRoot":"","sources":["../src/lazy.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH;;;GAGG;AACH,MAAa,IAAI;IAGhB;;;OAGG;IACH,YAAoC,cAAuB;QAAvB,mBAAc,GAAd,cAAc,CAAS;QALnD,eAAU,GAAY,KAAK,CAAC;IAK0B,CAAC;IAE/D;;OAEG;IACH,IAAW,SAAS;QACnB,OAAO,IAAI,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MAAM,CAAC;IACpB,CAAC;CACD;AA1CD,kCA0CC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\n/**\n * Helper class for lazy initialized values. Ensures the value is only generated once, and remain immutable.\n * @internal\n */\nexport class Lazy<T> {\n\tprivate _value: T | undefined;\n\tprivate _evaluated: boolean = false;\n\t/**\n\t * Instantiates an instance of Lazy<T>.\n\t * @param valueGenerator - The function that will generate the value when value is accessed the first time.\n\t */\n\tpublic constructor(private readonly valueGenerator: () => T) {}\n\n\t/**\n\t * Return true if the value as been generated, otherwise false.\n\t */\n\tpublic get evaluated(): boolean {\n\t\treturn this._evaluated;\n\t}\n\n\t/**\n\t * Get the value. If this is the first call the value will be generated.\n\t */\n\tpublic get value(): T {\n\t\tif (!this._evaluated) {\n\t\t\tthis._evaluated = true;\n\t\t\tthis._value = this.valueGenerator();\n\t\t}\n\t\t// eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n\t\treturn this._value!;\n\t}\n}\n\n/**\n * A lazy evaluated promise. The execute function is delayed until\n * the promise is used, e.g. await, then, catch ...\n * The execute function is only called once.\n * All calls are then proxied to the promise returned by the execute method.\n * @internal\n */\nexport class LazyPromise<T> implements Promise<T> {\n\tpublic get [Symbol.toStringTag](): string {\n\t\treturn this.getPromise()[Symbol.toStringTag];\n\t}\n\n\tprivate result: Promise<T> | undefined;\n\n\tpublic constructor(private readonly execute: () => Promise<T>) {}\n\n\t// eslint-disable-next-line unicorn/no-thenable\n\tpublic async then<TResult1 = T, TResult2 = never>(\n\t\t// eslint-disable-next-line @rushstack/no-new-null\n\t\tonfulfilled?: ((value: T) => TResult1 | PromiseLike<TResult1>) | null | undefined,\n\t\t// TODO: Use `unknown` instead (API breaking)\n\t\t// eslint-disable-next-line @rushstack/no-new-null, @typescript-eslint/no-explicit-any\n\t\tonrejected?: ((reason: any) => TResult2 | PromiseLike<TResult2>) | null | undefined,\n\t): Promise<TResult1 | TResult2> {\n\t\t// eslint-disable-next-line prefer-rest-params\n\t\treturn this.getPromise().then<TResult1, TResult2>(...arguments);\n\t}\n\n\tpublic async catch<TResult = never>(\n\t\t// TODO: Use `unknown` instead (API breaking)\n\t\t// eslint-disable-next-line @rushstack/no-new-null, @typescript-eslint/no-explicit-any\n\t\tonrejected?: ((reason: any) => TResult | PromiseLike<TResult>) | null | undefined,\n\t): Promise<T | TResult> {\n\t\t// eslint-disable-next-line prefer-rest-params\n\t\treturn this.getPromise().catch<TResult>(...arguments);\n\t}\n\n\t// eslint-disable-next-line @rushstack/no-new-null\n\tpublic async finally(onfinally?: (() => void) | null | undefined): Promise<T> {\n\t\t// eslint-disable-next-line prefer-rest-params\n\t\treturn this.getPromise().finally(...arguments);\n\t}\n\n\tprivate async getPromise(): Promise<T> {\n\t\tif (this.result === undefined) {\n\t\t\tthis.result = this.execute();\n\t\t}\n\t\treturn this.result;\n\t}\n}\n"]}
|
package/lib/promiseCache.d.ts
CHANGED
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
* - indefinite: entries don't expire and must be explicitly removed
|
|
8
8
|
* - absolute: entries expire after the given duration in MS, even if accessed multiple times in the mean time
|
|
9
9
|
* - sliding: entries expire after the given duration in MS of inactivity (i.e. get resets the clock)
|
|
10
|
-
* @
|
|
10
|
+
* @alpha
|
|
11
11
|
*/
|
|
12
12
|
export type PromiseCacheExpiry = {
|
|
13
13
|
policy: "indefinite";
|
|
@@ -17,7 +17,7 @@ export type PromiseCacheExpiry = {
|
|
|
17
17
|
};
|
|
18
18
|
/**
|
|
19
19
|
* Options for configuring the {@link PromiseCache}
|
|
20
|
-
* @
|
|
20
|
+
* @alpha
|
|
21
21
|
*/
|
|
22
22
|
export interface PromiseCacheOptions {
|
|
23
23
|
/**
|
|
@@ -32,7 +32,7 @@ export interface PromiseCacheOptions {
|
|
|
32
32
|
/**
|
|
33
33
|
* A specialized cache for async work, allowing you to safely cache the promised result of some async work
|
|
34
34
|
* without fear of running it multiple times or losing track of errors.
|
|
35
|
-
* @
|
|
35
|
+
* @alpha
|
|
36
36
|
*/
|
|
37
37
|
export declare class PromiseCache<TKey, TResult> {
|
|
38
38
|
private readonly cache;
|
package/lib/promiseCache.js
CHANGED
|
@@ -1,7 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
1
2
|
/*!
|
|
2
3
|
* Copyright (c) Microsoft Corporation and contributors. All rights reserved.
|
|
3
4
|
* Licensed under the MIT License.
|
|
4
5
|
*/
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
exports.PromiseCache = void 0;
|
|
5
8
|
/**
|
|
6
9
|
* Handles garbage collection of expiring cache entries.
|
|
7
10
|
* Not exported.
|
|
@@ -47,9 +50,9 @@ class GarbageCollector {
|
|
|
47
50
|
/**
|
|
48
51
|
* A specialized cache for async work, allowing you to safely cache the promised result of some async work
|
|
49
52
|
* without fear of running it multiple times or losing track of errors.
|
|
50
|
-
* @
|
|
53
|
+
* @alpha
|
|
51
54
|
*/
|
|
52
|
-
|
|
55
|
+
class PromiseCache {
|
|
53
56
|
/**
|
|
54
57
|
* Create the PromiseCache with the given options, with the following defaults:
|
|
55
58
|
*
|
|
@@ -141,4 +144,5 @@ export class PromiseCache {
|
|
|
141
144
|
return this.add(key, async () => value);
|
|
142
145
|
}
|
|
143
146
|
}
|
|
147
|
+
exports.PromiseCache = PromiseCache;
|
|
144
148
|
//# sourceMappingURL=promiseCache.js.map
|
package/lib/promiseCache.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"promiseCache.js","sourceRoot":"","sources":["../src/promiseCache.ts"],"names":[],"mappings":"AAAA;;;GAGG
|
|
1
|
+
{"version":3,"file":"promiseCache.js","sourceRoot":"","sources":["../src/promiseCache.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAmCH;;;GAGG;AACH,MAAM,gBAAgB;IAGrB,YACkB,MAA0B,EAC1B,OAA4B;QAD5B,WAAM,GAAN,MAAM,CAAoB;QAC1B,YAA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AC;YAEH,IAAI,CAAC,EAAE,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC;SACtB;QAED,OAAO,OAAO,CAAC;IAChB,CAAC;IAED;;;;;OAKG;IACI,GAAG,CAAC,GAAS,EAAE,OAA+B;QACpD,MAAM,cAAc,GAAG,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;QAErC,iGAAiG;QACjG,wGAAwG;QACxG,IAAI,CAAC,QAAQ,CAAC,GAAG,EAAE,OAAO,CAAC,CAAC,KAAK,CAAC,GAAG,EAAE,GAAE,CAAC,CAAC,CAAC;QAE5C,OAAO,CAAC,cAAc,CAAC;IACxB,CAAC;IAED;;;;;OAKG;IACI,KAAK,CAAC,aAAa,CAAC,GAAS,EAAE,KAAc;QACnD,OAAO,IAAI,CAAC,QAAQ,CAAC,GAAG,EAAE,KAAK,IAAI,EAAE,CAAC,KAAK,CAAC,CAAC;IAC9C,CAAC;IAED;;;;;OAKG;IACI,QAAQ,CAAC,GAAS,EAAE,KAAc;QACxC,OAAO,IAAI,CAAC,GAAG,CAAC,GAAG,EAAE,KAAK,IAAI,EAAE,CAAC,KAAK,CAAC,CAAC;IACzC,CAAC;CACD;AA/GD,oCA+GC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\n/**\n * Three supported expiry policies:\n * - indefinite: entries don't expire and must be explicitly removed\n * - absolute: entries expire after the given duration in MS, even if accessed multiple times in the mean time\n * - sliding: entries expire after the given duration in MS of inactivity (i.e. get resets the clock)\n * @alpha\n */\nexport type PromiseCacheExpiry =\n\t| {\n\t\t\tpolicy: \"indefinite\";\n\t }\n\t| {\n\t\t\tpolicy: \"absolute\" | \"sliding\";\n\t\t\tdurationMs: number;\n\t };\n\n/**\n * Options for configuring the {@link PromiseCache}\n * @alpha\n */\nexport interface PromiseCacheOptions {\n\t/**\n\t * Common expiration policy for all items added to this cache\n\t */\n\texpiry?: PromiseCacheExpiry;\n\t/**\n\t * If the stored Promise is rejected with a particular error, should the given key be removed?\n\t */\n\t// TODO: Use `unknown` instead (API breaking)\n\t// eslint-disable-next-line @typescript-eslint/no-explicit-any\n\tremoveOnError?: (error: any) => boolean;\n}\n\n/**\n * Handles garbage collection of expiring cache entries.\n * Not exported.\n */\nclass GarbageCollector<TKey> {\n\tprivate readonly gcTimeouts = new Map<TKey, ReturnType<typeof setTimeout>>();\n\n\tpublic constructor(\n\t\tprivate readonly expiry: PromiseCacheExpiry,\n\t\tprivate readonly cleanup: (key: TKey) => void,\n\t) {}\n\n\t/**\n\t * Schedule GC for the given key, as applicable\n\t */\n\tpublic schedule(key: TKey): void {\n\t\tif (this.expiry.policy !== \"indefinite\") {\n\t\t\tthis.gcTimeouts.set(\n\t\t\t\tkey,\n\t\t\t\tsetTimeout(() => {\n\t\t\t\t\tthis.cleanup(key);\n\t\t\t\t\tthis.cancel(key);\n\t\t\t\t}, this.expiry.durationMs),\n\t\t\t);\n\t\t}\n\t}\n\n\t/**\n\t * Cancel any pending GC for the given key\n\t */\n\tpublic cancel(key: TKey): void {\n\t\tconst timeout = this.gcTimeouts.get(key);\n\t\tif (timeout !== undefined) {\n\t\t\tclearTimeout(timeout);\n\t\t\tthis.gcTimeouts.delete(key);\n\t\t}\n\t}\n\n\t/**\n\t * Update any pending GC for the given key, as applicable\n\t */\n\tpublic update(key: TKey): void {\n\t\t// Cancel/reschedule new GC if the policy is sliding\n\t\tif (this.expiry.policy === \"sliding\") {\n\t\t\tthis.cancel(key);\n\t\t\tthis.schedule(key);\n\t\t}\n\t}\n}\n\n/**\n * A specialized cache for async work, allowing you to safely cache the promised result of some async work\n * without fear of running it multiple times or losing track of errors.\n * @alpha\n */\nexport class PromiseCache<TKey, TResult> {\n\tprivate readonly cache = new Map<TKey, Promise<TResult>>();\n\tprivate readonly gc: GarbageCollector<TKey>;\n\n\tprivate readonly removeOnError: (error: unknown) => boolean;\n\n\t/**\n\t * Create the PromiseCache with the given options, with the following defaults:\n\t *\n\t * expiry: indefinite, removeOnError: true for all errors\n\t */\n\tpublic constructor({\n\t\texpiry = { policy: \"indefinite\" },\n\t\tremoveOnError = (): boolean => true,\n\t}: PromiseCacheOptions = {}) {\n\t\tthis.removeOnError = removeOnError;\n\t\tthis.gc = new GarbageCollector<TKey>(expiry, (key) => this.remove(key));\n\t}\n\n\t/**\n\t * Check if there's anything cached at the given key\n\t */\n\tpublic has(key: TKey): boolean {\n\t\treturn this.cache.has(key);\n\t}\n\n\t/**\n\t * Get the Promise for the given key, or undefined if it's not found.\n\t * Extend expiry if applicable.\n\t */\n\tpublic get(key: TKey): Promise<TResult> | undefined {\n\t\tif (this.has(key)) {\n\t\t\tthis.gc.update(key);\n\t\t}\n\t\treturn this.cache.get(key);\n\t}\n\n\t/**\n\t * Remove the Promise for the given key, returning true if it was found and removed\n\t */\n\tpublic remove(key: TKey): boolean {\n\t\tthis.gc.cancel(key);\n\t\treturn this.cache.delete(key);\n\t}\n\n\t/**\n\t * Try to add the result of the given asyncFn, without overwriting an existing cache entry at that key.\n\t * Returns a Promise for the added or existing async work being done at that key.\n\t * @param key - key name where to store the async work\n\t * @param asyncFn - the async work to do and store, if not already in progress under the given key\n\t */\n\tpublic async addOrGet(key: TKey, asyncFn: () => Promise<TResult>): Promise<TResult> {\n\t\t// NOTE: Do not await the Promise returned by asyncFn!\n\t\t// Let the caller do so once we return or after a subsequent call to get\n\t\tlet promise = this.get(key);\n\t\tif (promise === undefined) {\n\t\t\t// Wrap in an async lambda in case asyncFn disabled @typescript-eslint/promise-function-async\n\t\t\tconst safeAsyncFn = async (): Promise<TResult> => asyncFn();\n\n\t\t\t// Start the async work and put the Promise in the cache\n\t\t\tpromise = safeAsyncFn();\n\t\t\tthis.cache.set(key, promise);\n\n\t\t\t// If asyncFn throws, we may remove the Promise from the cache\n\t\t\tpromise.catch((error) => {\n\t\t\t\tif (this.removeOnError(error)) {\n\t\t\t\t\tthis.remove(key);\n\t\t\t\t}\n\t\t\t});\n\n\t\t\tthis.gc.schedule(key);\n\t\t}\n\n\t\treturn promise;\n\t}\n\n\t/**\n\t * Try to add the result of the given asyncFn, without overwriting an existing cache entry at that key.\n\t * Returns false if the cache already contained an entry at that key, and true otherwise.\n\t * @param key - key name where to store the async work\n\t * @param asyncFn - the async work to do and store, if not already in progress under the given key\n\t */\n\tpublic add(key: TKey, asyncFn: () => Promise<TResult>): boolean {\n\t\tconst alreadyPresent = this.has(key);\n\n\t\t// We are blindly adding the Promise to the cache here, which introduces a Promise in this scope.\n\t\t// Swallow Promise rejections here, since whoever gets this out of the cache to use it will await/catch.\n\t\tthis.addOrGet(key, asyncFn).catch(() => {});\n\n\t\treturn !alreadyPresent;\n\t}\n\n\t/**\n\t * Try to add the given value, without overwriting an existing cache entry at that key.\n\t * Returns a Promise for the added or existing async work being done at that key.\n\t * @param key - key name where to store the async work\n\t * @param value - value to store\n\t */\n\tpublic async addValueOrGet(key: TKey, value: TResult): Promise<TResult> {\n\t\treturn this.addOrGet(key, async () => value);\n\t}\n\n\t/**\n\t * Try to add the given value, without overwriting an existing cache entry at that key.\n\t * Returns false if the cache already contained an entry at that key, and true otherwise.\n\t * @param key - key name where to store the value\n\t * @param value - value to store\n\t */\n\tpublic addValue(key: TKey, value: TResult): boolean {\n\t\treturn this.add(key, async () => value);\n\t}\n}\n"]}
|
package/lib/promises.d.ts
CHANGED
package/lib/promises.js
CHANGED
|
@@ -1,12 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
1
2
|
/*!
|
|
2
3
|
* Copyright (c) Microsoft Corporation and contributors. All rights reserved.
|
|
3
4
|
* Licensed under the MIT License.
|
|
4
5
|
*/
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
exports.Deferred = void 0;
|
|
5
8
|
/**
|
|
6
9
|
* A deferred creates a promise and the ability to resolve or reject it
|
|
7
|
-
* @
|
|
10
|
+
* @alpha
|
|
8
11
|
*/
|
|
9
|
-
|
|
12
|
+
class Deferred {
|
|
10
13
|
constructor() {
|
|
11
14
|
this.completed = false;
|
|
12
15
|
this.p = new Promise((resolve, reject) => {
|
|
@@ -53,4 +56,5 @@ export class Deferred {
|
|
|
53
56
|
}
|
|
54
57
|
}
|
|
55
58
|
}
|
|
59
|
+
exports.Deferred = Deferred;
|
|
56
60
|
//# sourceMappingURL=promises.js.map
|
package/lib/promises.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"promises.js","sourceRoot":"","sources":["../src/promises.ts"],"names":[],"mappings":"AAAA;;;GAGG
|
|
1
|
+
{"version":3,"file":"promises.js","sourceRoot":"","sources":["../src/promises.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH;;;GAGG;AACH,MAAa,QAAQ;IAMpB;QAFQ,cAAS,GAAY,KAAK,CAAC;QAGlC,IAAI,CAAC,CAAC,GAAG,IAAI,OAAO,CAAI,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;YAC3C,IAAI,CAAC,GAAG,GAAG,OAAO,CAAC;YACnB,IAAI,CAAC,GAAG,GAAG,MAAM,CAAC;QACnB,CAAC,CAAC,CAAC;IACJ,CAAC;IACD;;OAEG;IACH,IAAW,WAAW;QACrB,OAAO,IAAI,CAAC,SAAS,CAAC;IACvB,CAAC;IAED;;;;OAIG;IACH,IAAW,OAAO;QACjB,OAAO,IAAI,CAAC,CAAC,CAAC;IACf,CAAC;IAED;;;;OAIG;IACI,OAAO,CAAC,KAAyB;QACvC,IAAI,IAAI,CAAC,GAAG,KAAK,SAAS,EAAE;YAC3B,IAAI,CAAC,SAAS,GAAG,IAAI,CAAC;YACtB,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;SAChB;IACF,CAAC;IAED;;;;OAIG;IACH,6CAA6C;IAC7C,iHAAiH;IAC1G,MAAM,CAAC,KAAU;QACvB,IAAI,IAAI,CAAC,GAAG,KAAK,SAAS,EAAE;YAC3B,IAAI,CAAC,SAAS,GAAG,IAAI,CAAC;YACtB,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;SAChB;IACF,CAAC;CACD;AArDD,4BAqDC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\n/**\n * A deferred creates a promise and the ability to resolve or reject it\n * @alpha\n */\nexport class Deferred<T> {\n\tprivate readonly p: Promise<T>;\n\tprivate res: ((value: T | PromiseLike<T>) => void) | undefined;\n\tprivate rej: ((reason?: unknown) => void) | undefined;\n\tprivate completed: boolean = false;\n\n\tpublic constructor() {\n\t\tthis.p = new Promise<T>((resolve, reject) => {\n\t\t\tthis.res = resolve;\n\t\t\tthis.rej = reject;\n\t\t});\n\t}\n\t/**\n\t * Returns whether the underlying promise has been completed\n\t */\n\tpublic get isCompleted(): boolean {\n\t\treturn this.completed;\n\t}\n\n\t/**\n\t * Retrieves the underlying promise for the deferred\n\t *\n\t * @returns the underlying promise\n\t */\n\tpublic get promise(): Promise<T> {\n\t\treturn this.p;\n\t}\n\n\t/**\n\t * Resolves the promise\n\t *\n\t * @param value - the value to resolve the promise with\n\t */\n\tpublic resolve(value: T | PromiseLike<T>): void {\n\t\tif (this.res !== undefined) {\n\t\t\tthis.completed = true;\n\t\t\tthis.res(value);\n\t\t}\n\t}\n\n\t/**\n\t * Rejects the promise\n\t *\n\t * @param value - the value to reject the promise with\n\t */\n\t// TODO: Use `unknown` instead (API breaking)\n\t// eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/explicit-module-boundary-types\n\tpublic reject(error: any): void {\n\t\tif (this.rej !== undefined) {\n\t\t\tthis.completed = true;\n\t\t\tthis.rej(error);\n\t\t}\n\t}\n}\n"]}
|
package/lib/timer.js
CHANGED
|
@@ -1,9 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
1
2
|
/*!
|
|
2
3
|
* Copyright (c) Microsoft Corporation and contributors. All rights reserved.
|
|
3
4
|
* Licensed under the MIT License.
|
|
4
5
|
*/
|
|
5
|
-
|
|
6
|
-
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
exports.PromiseTimer = exports.Timer = exports.setLongTimeout = void 0;
|
|
8
|
+
const assert_1 = require("./assert");
|
|
9
|
+
const promises_1 = require("./promises");
|
|
7
10
|
const maxSetTimeoutMs = 0x7fffffff; // setTimeout limit is MAX_INT32=(2^31-1).
|
|
8
11
|
/**
|
|
9
12
|
* Sets timeouts like the setTimeout function allowing timeouts to exceed the setTimeout's max timeout limit.
|
|
@@ -16,7 +19,7 @@ const maxSetTimeoutMs = 0x7fffffff; // setTimeout limit is MAX_INT32=(2^31-1).
|
|
|
16
19
|
* @returns The initial timeout
|
|
17
20
|
* @internal
|
|
18
21
|
*/
|
|
19
|
-
|
|
22
|
+
function setLongTimeout(timeoutFn, timeoutMs, setTimeoutIdFn) {
|
|
20
23
|
// The setTimeout max is 24.8 days before looping occurs.
|
|
21
24
|
let timeoutId;
|
|
22
25
|
if (timeoutMs > maxSetTimeoutMs) {
|
|
@@ -29,6 +32,7 @@ export function setLongTimeout(timeoutFn, timeoutMs, setTimeoutIdFn) {
|
|
|
29
32
|
setTimeoutIdFn?.(timeoutId);
|
|
30
33
|
return timeoutId;
|
|
31
34
|
}
|
|
35
|
+
exports.setLongTimeout = setLongTimeout;
|
|
32
36
|
/**
|
|
33
37
|
* This class is a thin wrapper over setTimeout and clearTimeout which
|
|
34
38
|
* makes it simpler to keep track of recurring timeouts with the same
|
|
@@ -36,7 +40,7 @@ export function setLongTimeout(timeoutFn, timeoutMs, setTimeoutIdFn) {
|
|
|
36
40
|
* or timeouts exceeding (2^31)-1 ms or approximately 24.8 days.
|
|
37
41
|
* @internal
|
|
38
42
|
*/
|
|
39
|
-
|
|
43
|
+
class Timer {
|
|
40
44
|
/**
|
|
41
45
|
* Returns true if the timer is running.
|
|
42
46
|
*/
|
|
@@ -121,7 +125,7 @@ export class Timer {
|
|
|
121
125
|
};
|
|
122
126
|
}
|
|
123
127
|
handler() {
|
|
124
|
-
assert(!!this.runningState, 0x764 /* Running timer missing handler */);
|
|
128
|
+
(0, assert_1.assert)(!!this.runningState, 0x764 /* Running timer missing handler */);
|
|
125
129
|
const restart = this.runningState.restart;
|
|
126
130
|
if (restart === undefined) {
|
|
127
131
|
// Run clear first, in case the handler decides to start again
|
|
@@ -140,6 +144,7 @@ export class Timer {
|
|
|
140
144
|
return runningTimeout.duration - elapsedTime;
|
|
141
145
|
}
|
|
142
146
|
}
|
|
147
|
+
exports.Timer = Timer;
|
|
143
148
|
/**
|
|
144
149
|
* This class is a wrapper over setTimeout and clearTimeout which
|
|
145
150
|
* makes it simpler to keep track of recurring timeouts with the
|
|
@@ -147,7 +152,7 @@ export class Timer {
|
|
|
147
152
|
* resolves when it times out.
|
|
148
153
|
* @internal
|
|
149
154
|
*/
|
|
150
|
-
|
|
155
|
+
class PromiseTimer {
|
|
151
156
|
/**
|
|
152
157
|
* {@inheritDoc Timer.hasTimer}
|
|
153
158
|
*/
|
|
@@ -162,7 +167,7 @@ export class PromiseTimer {
|
|
|
162
167
|
*/
|
|
163
168
|
async start(ms, handler) {
|
|
164
169
|
this.clear();
|
|
165
|
-
this.deferred = new Deferred();
|
|
170
|
+
this.deferred = new promises_1.Deferred();
|
|
166
171
|
this.timer.start(ms, handler ? () => this.wrapHandler(handler) : undefined);
|
|
167
172
|
return this.deferred.promise;
|
|
168
173
|
}
|
|
@@ -175,9 +180,10 @@ export class PromiseTimer {
|
|
|
175
180
|
}
|
|
176
181
|
wrapHandler(handler) {
|
|
177
182
|
handler();
|
|
178
|
-
assert(!!this.deferred, 0x765 /* Handler executed without deferred */);
|
|
183
|
+
(0, assert_1.assert)(!!this.deferred, 0x765 /* Handler executed without deferred */);
|
|
179
184
|
this.deferred.resolve({ timerResult: "timeout" });
|
|
180
185
|
this.deferred = undefined;
|
|
181
186
|
}
|
|
182
187
|
}
|
|
188
|
+
exports.PromiseTimer = PromiseTimer;
|
|
183
189
|
//# sourceMappingURL=timer.js.map
|
package/lib/timer.js.map
CHANGED
|
@@ -1 +1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,CAAC;CACD","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { assert } from \"./assert\";\nimport { Deferred } from \"./promises\";\n\n/**\n * @internal\n */\nexport interface ITimer {\n\t/**\n\t * True if timer is currently running\n\t */\n\treadonly hasTimer: boolean;\n\n\t/**\n\t * Starts the timer\n\t */\n\tstart(): void;\n\n\t/**\n\t * Cancels the timer if already running\n\t */\n\tclear(): void;\n}\n\ninterface ITimeout {\n\t/**\n\t * Tick that timeout was started.\n\t */\n\tstartTick: number;\n\n\t/**\n\t * Timeout duration in ms.\n\t */\n\tduration: number;\n\n\t/**\n\t * Handler to execute when timeout ends.\n\t */\n\thandler: () => void;\n}\n\ninterface IRunningTimerState extends ITimeout {\n\t/**\n\t * JavaScript Timeout object.\n\t */\n\ttimeout: ReturnType<typeof setTimeout>;\n\n\t/**\n\t * Intended duration in ms.\n\t */\n\tintendedDuration: number;\n\n\t/**\n\t * Intended restart timeout.\n\t */\n\trestart?: ITimeout;\n}\n\nconst maxSetTimeoutMs = 0x7fffffff; // setTimeout limit is MAX_INT32=(2^31-1).\n\n/**\n * Sets timeouts like the setTimeout function allowing timeouts to exceed the setTimeout's max timeout limit.\n * Timeouts may not be exactly accurate due to browser implementations and the OS.\n * https://stackoverflow.com/questions/21097421/what-is-the-reason-javascript-settimeout-is-so-inaccurate\n * @param timeoutFn - Executed when the timeout expires\n * @param timeoutMs - Duration of the timeout in milliseconds\n * @param setTimeoutIdFn - Executed to update the timeout if multiple timeouts are required when\n * timeoutMs greater than maxTimeout\n * @returns The initial timeout\n * @internal\n */\nexport function setLongTimeout(\n\ttimeoutFn: () => void,\n\ttimeoutMs: number,\n\tsetTimeoutIdFn?: (timeoutId: ReturnType<typeof setTimeout>) => void,\n): ReturnType<typeof setTimeout> {\n\t// The setTimeout max is 24.8 days before looping occurs.\n\tlet timeoutId: ReturnType<typeof setTimeout>;\n\tif (timeoutMs > maxSetTimeoutMs) {\n\t\tconst newTimeoutMs = timeoutMs - maxSetTimeoutMs;\n\t\ttimeoutId = setTimeout(\n\t\t\t() => setLongTimeout(timeoutFn, newTimeoutMs, setTimeoutIdFn),\n\t\t\tmaxSetTimeoutMs,\n\t\t);\n\t} else {\n\t\ttimeoutId = setTimeout(() => timeoutFn(), Math.max(timeoutMs, 0));\n\t}\n\n\tsetTimeoutIdFn?.(timeoutId);\n\treturn timeoutId;\n}\n\n/**\n * This class is a thin wrapper over setTimeout and clearTimeout which\n * makes it simpler to keep track of recurring timeouts with the same\n * or similar handlers and timeouts. This class supports long timeouts\n * or timeouts exceeding (2^31)-1 ms or approximately 24.8 days.\n * @internal\n */\nexport class Timer implements ITimer {\n\t/**\n\t * Returns true if the timer is running.\n\t */\n\tpublic get hasTimer(): boolean {\n\t\treturn !!this.runningState;\n\t}\n\n\tprivate runningState: IRunningTimerState | undefined;\n\n\tpublic constructor(\n\t\tprivate readonly defaultTimeout: number,\n\t\tprivate readonly defaultHandler: () => void,\n\t\tprivate readonly getCurrentTick: () => number = (): number => Date.now(),\n\t) {}\n\n\t/**\n\t * Calls setTimeout and tracks the resulting timeout.\n\t * @param ms - overrides default timeout in ms\n\t * @param handler - overrides default handler\n\t */\n\tpublic start(\n\t\tms: number = this.defaultTimeout,\n\t\thandler: () => void = this.defaultHandler,\n\t): void {\n\t\tthis.startCore(ms, handler, ms);\n\t}\n\n\t/**\n\t * Calls clearTimeout on the underlying timeout if running.\n\t */\n\tpublic clear(): void {\n\t\tif (!this.runningState) {\n\t\t\treturn;\n\t\t}\n\t\tclearTimeout(this.runningState.timeout);\n\t\tthis.runningState = undefined;\n\t}\n\n\t/**\n\t * Restarts the timer with the new handler and duration.\n\t * If a new handler is passed, the original handler may\n\t * never execute.\n\t * This is a potentially more efficient way to clear and start\n\t * a new timer.\n\t * @param ms - overrides previous or default timeout in ms\n\t * @param handler - overrides previous or default handler\n\t */\n\tpublic restart(ms?: number, handler?: () => void): void {\n\t\tif (this.runningState) {\n\t\t\tconst duration = ms ?? this.runningState.intendedDuration;\n\t\t\tconst handlerToUse =\n\t\t\t\thandler ?? this.runningState.restart?.handler ?? this.runningState.handler;\n\t\t\tconst remainingTime = this.calculateRemainingTime(this.runningState);\n\n\t\t\tif (duration < remainingTime) {\n\t\t\t\t// If remaining time exceeds restart duration, do a hard restart.\n\t\t\t\t// The existing timeout time is too long.\n\t\t\t\tthis.start(duration, handlerToUse);\n\t\t\t} else if (duration === remainingTime) {\n\t\t\t\t// The existing timeout time is perfect, just update handler and data.\n\t\t\t\tthis.runningState.handler = handlerToUse;\n\t\t\t\tthis.runningState.restart = undefined;\n\t\t\t\tthis.runningState.intendedDuration = duration;\n\t\t\t} else {\n\t\t\t\t// If restart duration exceeds remaining time, set restart info.\n\t\t\t\t// Existing timeout will start a new timeout for remaining time.\n\t\t\t\tthis.runningState.restart = {\n\t\t\t\t\tstartTick: this.getCurrentTick(),\n\t\t\t\t\tduration,\n\t\t\t\t\thandler: handlerToUse,\n\t\t\t\t};\n\t\t\t}\n\t\t} else {\n\t\t\t// If restart is called first, it behaves as a call to start\n\t\t\tthis.start(ms, handler);\n\t\t}\n\t}\n\n\tprivate startCore(duration: number, handler: () => void, intendedDuration: number): void {\n\t\tthis.clear();\n\t\tthis.runningState = {\n\t\t\tstartTick: this.getCurrentTick(),\n\t\t\tduration,\n\t\t\tintendedDuration,\n\t\t\thandler,\n\t\t\ttimeout: setLongTimeout(\n\t\t\t\t() => this.handler(),\n\t\t\t\tduration,\n\t\t\t\t(timer: number) => {\n\t\t\t\t\tif (this.runningState !== undefined) {\n\t\t\t\t\t\tthis.runningState.timeout = timer;\n\t\t\t\t\t}\n\t\t\t\t},\n\t\t\t),\n\t\t};\n\t}\n\n\tprivate handler(): void {\n\t\tassert(!!this.runningState, 0x764 /* Running timer missing handler */);\n\t\tconst restart = this.runningState.restart;\n\t\tif (restart === undefined) {\n\t\t\t// Run clear first, in case the handler decides to start again\n\t\t\tconst handler = this.runningState.handler;\n\t\t\tthis.clear();\n\t\t\thandler();\n\t\t} else {\n\t\t\t// Restart with remaining time\n\t\t\tconst remainingTime = this.calculateRemainingTime(restart);\n\t\t\tthis.startCore(remainingTime, () => restart.handler(), restart.duration);\n\t\t}\n\t}\n\n\tprivate calculateRemainingTime(runningTimeout: ITimeout): number {\n\t\tconst elapsedTime = this.getCurrentTick() - runningTimeout.startTick;\n\t\treturn runningTimeout.duration - elapsedTime;\n\t}\n}\n\n/**\n * @internal\n */\nexport interface IPromiseTimerResult {\n\ttimerResult: \"timeout\" | \"cancel\";\n}\n\n/**\n * Timer which offers a promise that fulfills when the timer\n * completes.\n * @internal\n */\nexport interface IPromiseTimer extends ITimer {\n\t/**\n\t * Starts the timer and returns a promise that\n\t * resolves when the timer times out or is canceled.\n\t */\n\tstart(): Promise<IPromiseTimerResult>;\n}\n\n/**\n * This class is a wrapper over setTimeout and clearTimeout which\n * makes it simpler to keep track of recurring timeouts with the\n * same handlers and timeouts, while also providing a promise that\n * resolves when it times out.\n * @internal\n */\nexport class PromiseTimer implements IPromiseTimer {\n\tprivate deferred?: Deferred<IPromiseTimerResult>;\n\tprivate readonly timer: Timer;\n\n\t/**\n\t * {@inheritDoc Timer.hasTimer}\n\t */\n\tpublic get hasTimer(): boolean {\n\t\treturn this.timer.hasTimer;\n\t}\n\n\tpublic constructor(defaultTimeout: number, defaultHandler: () => void) {\n\t\tthis.timer = new Timer(defaultTimeout, () => this.wrapHandler(defaultHandler));\n\t}\n\n\t/**\n\t * {@inheritDoc IPromiseTimer.start}\n\t */\n\tpublic async start(ms?: number, handler?: () => void): Promise<IPromiseTimerResult> {\n\t\tthis.clear();\n\t\tthis.deferred = new Deferred<IPromiseTimerResult>();\n\t\tthis.timer.start(ms, handler ? (): void => this.wrapHandler(handler) : undefined);\n\t\treturn this.deferred.promise;\n\t}\n\n\tpublic clear(): void {\n\t\tthis.timer.clear();\n\t\tif (this.deferred) {\n\t\t\tthis.deferred.resolve({ timerResult: \"cancel\" });\n\t\t\tthis.deferred = undefined;\n\t\t}\n\t}\n\n\tprotected wrapHandler(handler: () => void): void {\n\t\thandler();\n\t\tassert(!!this.deferred, 0x765 /* Handler executed without deferred */);\n\t\tthis.deferred.resolve({ timerResult: \"timeout\" });\n\t\tthis.deferred = undefined;\n\t}\n}\n"]}
|
|
1
|
+
{"version":3,"file":"timer.js","sourceRoot":"","sources":["../src/timer.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH,qCAAkC;AAClC,yCAAsC;AAwDtC,MAAM,eAAe,GAAG,UAAU,CAAC,CAAC,0CAA0C;AAE9E;;;;;;;;;;GAUG;AACH,SAAgB,cAAc,CAC7B,SAAqB,EACrB,SAAiB,EACjB,cAAmE;IAEnE,yDAAyD;IACzD,IAAI,SAAwC,CAAC;IAC7C,IAAI,SAAS,GAAG,eAAe,EAAE;QAChC,MAAM,YAAY,GAAG,SAAS,GAAG,eAAe,CAAC;QACjD,SAAS,GAAG,UAAU,CACrB,GAAG,EAAE,CAAC,cAAc,CAAC,SAAS,EAAE,YAAY,EAAE,cAAc,CAAC,EAC7D,eAAe,CACf,CAAC;KACF;SAAM;QACN,SAAS,GAAG,UAAU,CAAC,GAAG,EAAE,CAAC,SAAS,EAAE,EAAE,IAAI,CAAC,GAAG,CAAC,SAAS,EAAE,CAAC,CAAC,CAAC,CAAC;KAClE;IAED,cAAc,EAAE,CAAC,SAAS,CAAC,CAAC;IAC5B,OAAO,SAAS,CAAC;AAClB,CAAC;AAnBD,wCAmBC;AAED;;;;;;GAMG;AACH,MAAa,KAAK;IACjB;;OAEG;IACH,IAAW,QAAQ;QAClB,OAAO,CAAC,CAAC,IAAI,CAAC,YAAY,CAAC;IAC5B,CAAC;IAID,YACkB,cAAsB,EACtB,cAA0B,EAC1B,iBAA+B,GAAW,EAAE,CAAC,IAAI,CAAC,GAAG,EAAE;QAFvD,mBAAc,GAAd,cAAc,CAAQ;QACtB,mBAAc,GAAd,cAAc,CAAY;QAC1B,mBAAc,GAAd,cAAc,CAAyC;IACtE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E,IAAI,CAAC,QAAQ,CAAC,OAAO,CAAC,EAAE,WAAW,EAAE,SAAS,EAAE,CAAC,CAAC;QAClD,IAAI,CAAC,QAAQ,GAAG,SAAS,CAAC;IAC3B,CAAC;CACD;AAvCD,oCAuCC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { assert } from \"./assert\";\nimport { Deferred } from \"./promises\";\n\n/**\n * @internal\n */\nexport interface ITimer {\n\t/**\n\t * True if timer is currently running\n\t */\n\treadonly hasTimer: boolean;\n\n\t/**\n\t * Starts the timer\n\t */\n\tstart(): void;\n\n\t/**\n\t * Cancels the timer if already running\n\t */\n\tclear(): void;\n}\n\ninterface ITimeout {\n\t/**\n\t * Tick that timeout was started.\n\t */\n\tstartTick: number;\n\n\t/**\n\t * Timeout duration in ms.\n\t */\n\tduration: number;\n\n\t/**\n\t * Handler to execute when timeout ends.\n\t */\n\thandler: () => void;\n}\n\ninterface IRunningTimerState extends ITimeout {\n\t/**\n\t * JavaScript Timeout object.\n\t */\n\ttimeout: ReturnType<typeof setTimeout>;\n\n\t/**\n\t * Intended duration in ms.\n\t */\n\tintendedDuration: number;\n\n\t/**\n\t * Intended restart timeout.\n\t */\n\trestart?: ITimeout;\n}\n\nconst maxSetTimeoutMs = 0x7fffffff; // setTimeout limit is MAX_INT32=(2^31-1).\n\n/**\n * Sets timeouts like the setTimeout function allowing timeouts to exceed the setTimeout's max timeout limit.\n * Timeouts may not be exactly accurate due to browser implementations and the OS.\n * https://stackoverflow.com/questions/21097421/what-is-the-reason-javascript-settimeout-is-so-inaccurate\n * @param timeoutFn - Executed when the timeout expires\n * @param timeoutMs - Duration of the timeout in milliseconds\n * @param setTimeoutIdFn - Executed to update the timeout if multiple timeouts are required when\n * timeoutMs greater than maxTimeout\n * @returns The initial timeout\n * @internal\n */\nexport function setLongTimeout(\n\ttimeoutFn: () => void,\n\ttimeoutMs: number,\n\tsetTimeoutIdFn?: (timeoutId: ReturnType<typeof setTimeout>) => void,\n): ReturnType<typeof setTimeout> {\n\t// The setTimeout max is 24.8 days before looping occurs.\n\tlet timeoutId: ReturnType<typeof setTimeout>;\n\tif (timeoutMs > maxSetTimeoutMs) {\n\t\tconst newTimeoutMs = timeoutMs - maxSetTimeoutMs;\n\t\ttimeoutId = setTimeout(\n\t\t\t() => setLongTimeout(timeoutFn, newTimeoutMs, setTimeoutIdFn),\n\t\t\tmaxSetTimeoutMs,\n\t\t);\n\t} else {\n\t\ttimeoutId = setTimeout(() => timeoutFn(), Math.max(timeoutMs, 0));\n\t}\n\n\tsetTimeoutIdFn?.(timeoutId);\n\treturn timeoutId;\n}\n\n/**\n * This class is a thin wrapper over setTimeout and clearTimeout which\n * makes it simpler to keep track of recurring timeouts with the same\n * or similar handlers and timeouts. This class supports long timeouts\n * or timeouts exceeding (2^31)-1 ms or approximately 24.8 days.\n * @internal\n */\nexport class Timer implements ITimer {\n\t/**\n\t * Returns true if the timer is running.\n\t */\n\tpublic get hasTimer(): boolean {\n\t\treturn !!this.runningState;\n\t}\n\n\tprivate runningState: IRunningTimerState | undefined;\n\n\tpublic constructor(\n\t\tprivate readonly defaultTimeout: number,\n\t\tprivate readonly defaultHandler: () => void,\n\t\tprivate readonly getCurrentTick: () => number = (): number => Date.now(),\n\t) {}\n\n\t/**\n\t * Calls setTimeout and tracks the resulting timeout.\n\t * @param ms - overrides default timeout in ms\n\t * @param handler - overrides default handler\n\t */\n\tpublic start(\n\t\tms: number = this.defaultTimeout,\n\t\thandler: () => void = this.defaultHandler,\n\t): void {\n\t\tthis.startCore(ms, handler, ms);\n\t}\n\n\t/**\n\t * Calls clearTimeout on the underlying timeout if running.\n\t */\n\tpublic clear(): void {\n\t\tif (!this.runningState) {\n\t\t\treturn;\n\t\t}\n\t\tclearTimeout(this.runningState.timeout);\n\t\tthis.runningState = undefined;\n\t}\n\n\t/**\n\t * Restarts the timer with the new handler and duration.\n\t * If a new handler is passed, the original handler may\n\t * never execute.\n\t * This is a potentially more efficient way to clear and start\n\t * a new timer.\n\t * @param ms - overrides previous or default timeout in ms\n\t * @param handler - overrides previous or default handler\n\t */\n\tpublic restart(ms?: number, handler?: () => void): void {\n\t\tif (this.runningState) {\n\t\t\tconst duration = ms ?? this.runningState.intendedDuration;\n\t\t\tconst handlerToUse =\n\t\t\t\thandler ?? this.runningState.restart?.handler ?? this.runningState.handler;\n\t\t\tconst remainingTime = this.calculateRemainingTime(this.runningState);\n\n\t\t\tif (duration < remainingTime) {\n\t\t\t\t// If remaining time exceeds restart duration, do a hard restart.\n\t\t\t\t// The existing timeout time is too long.\n\t\t\t\tthis.start(duration, handlerToUse);\n\t\t\t} else if (duration === remainingTime) {\n\t\t\t\t// The existing timeout time is perfect, just update handler and data.\n\t\t\t\tthis.runningState.handler = handlerToUse;\n\t\t\t\tthis.runningState.restart = undefined;\n\t\t\t\tthis.runningState.intendedDuration = duration;\n\t\t\t} else {\n\t\t\t\t// If restart duration exceeds remaining time, set restart info.\n\t\t\t\t// Existing timeout will start a new timeout for remaining time.\n\t\t\t\tthis.runningState.restart = {\n\t\t\t\t\tstartTick: this.getCurrentTick(),\n\t\t\t\t\tduration,\n\t\t\t\t\thandler: handlerToUse,\n\t\t\t\t};\n\t\t\t}\n\t\t} else {\n\t\t\t// If restart is called first, it behaves as a call to start\n\t\t\tthis.start(ms, handler);\n\t\t}\n\t}\n\n\tprivate startCore(duration: number, handler: () => void, intendedDuration: number): void {\n\t\tthis.clear();\n\t\tthis.runningState = {\n\t\t\tstartTick: this.getCurrentTick(),\n\t\t\tduration,\n\t\t\tintendedDuration,\n\t\t\thandler,\n\t\t\ttimeout: setLongTimeout(\n\t\t\t\t() => this.handler(),\n\t\t\t\tduration,\n\t\t\t\t(timer: number) => {\n\t\t\t\t\tif (this.runningState !== undefined) {\n\t\t\t\t\t\tthis.runningState.timeout = timer;\n\t\t\t\t\t}\n\t\t\t\t},\n\t\t\t),\n\t\t};\n\t}\n\n\tprivate handler(): void {\n\t\tassert(!!this.runningState, 0x764 /* Running timer missing handler */);\n\t\tconst restart = this.runningState.restart;\n\t\tif (restart === undefined) {\n\t\t\t// Run clear first, in case the handler decides to start again\n\t\t\tconst handler = this.runningState.handler;\n\t\t\tthis.clear();\n\t\t\thandler();\n\t\t} else {\n\t\t\t// Restart with remaining time\n\t\t\tconst remainingTime = this.calculateRemainingTime(restart);\n\t\t\tthis.startCore(remainingTime, () => restart.handler(), restart.duration);\n\t\t}\n\t}\n\n\tprivate calculateRemainingTime(runningTimeout: ITimeout): number {\n\t\tconst elapsedTime = this.getCurrentTick() - runningTimeout.startTick;\n\t\treturn runningTimeout.duration - elapsedTime;\n\t}\n}\n\n/**\n * @internal\n */\nexport interface IPromiseTimerResult {\n\ttimerResult: \"timeout\" | \"cancel\";\n}\n\n/**\n * Timer which offers a promise that fulfills when the timer\n * completes.\n * @internal\n */\nexport interface IPromiseTimer extends ITimer {\n\t/**\n\t * Starts the timer and returns a promise that\n\t * resolves when the timer times out or is canceled.\n\t */\n\tstart(): Promise<IPromiseTimerResult>;\n}\n\n/**\n * This class is a wrapper over setTimeout and clearTimeout which\n * makes it simpler to keep track of recurring timeouts with the\n * same handlers and timeouts, while also providing a promise that\n * resolves when it times out.\n * @internal\n */\nexport class PromiseTimer implements IPromiseTimer {\n\tprivate deferred?: Deferred<IPromiseTimerResult>;\n\tprivate readonly timer: Timer;\n\n\t/**\n\t * {@inheritDoc Timer.hasTimer}\n\t */\n\tpublic get hasTimer(): boolean {\n\t\treturn this.timer.hasTimer;\n\t}\n\n\tpublic constructor(defaultTimeout: number, defaultHandler: () => void) {\n\t\tthis.timer = new Timer(defaultTimeout, () => this.wrapHandler(defaultHandler));\n\t}\n\n\t/**\n\t * {@inheritDoc IPromiseTimer.start}\n\t */\n\tpublic async start(ms?: number, handler?: () => void): Promise<IPromiseTimerResult> {\n\t\tthis.clear();\n\t\tthis.deferred = new Deferred<IPromiseTimerResult>();\n\t\tthis.timer.start(ms, handler ? (): void => this.wrapHandler(handler) : undefined);\n\t\treturn this.deferred.promise;\n\t}\n\n\tpublic clear(): void {\n\t\tthis.timer.clear();\n\t\tif (this.deferred) {\n\t\t\tthis.deferred.resolve({ timerResult: \"cancel\" });\n\t\t\tthis.deferred = undefined;\n\t\t}\n\t}\n\n\tprotected wrapHandler(handler: () => void): void {\n\t\thandler();\n\t\tassert(!!this.deferred, 0x765 /* Handler executed without deferred */);\n\t\tthis.deferred.resolve({ timerResult: \"timeout\" });\n\t\tthis.deferred = undefined;\n\t}\n}\n"]}
|
package/lib/unreachable.js
CHANGED
|
@@ -1,7 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
1
2
|
/*!
|
|
2
3
|
* Copyright (c) Microsoft Corporation and contributors. All rights reserved.
|
|
3
4
|
* Licensed under the MIT License.
|
|
4
5
|
*/
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
exports.unreachableCase = void 0;
|
|
5
8
|
/**
|
|
6
9
|
* This function can be used to assert at compile time that a given value has type never.
|
|
7
10
|
* One common usage is in the default case of a switch block,
|
|
@@ -18,7 +21,8 @@
|
|
|
18
21
|
* ```
|
|
19
22
|
* @internal
|
|
20
23
|
*/
|
|
21
|
-
|
|
24
|
+
function unreachableCase(_, message = "Unreachable Case") {
|
|
22
25
|
throw new Error(message);
|
|
23
26
|
}
|
|
27
|
+
exports.unreachableCase = unreachableCase;
|
|
24
28
|
//# sourceMappingURL=unreachable.js.map
|
package/lib/unreachable.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"unreachable.js","sourceRoot":"","sources":["../src/unreachable.ts"],"names":[],"mappings":"AAAA;;;GAGG
|
|
1
|
+
{"version":3,"file":"unreachable.js","sourceRoot":"","sources":["../src/unreachable.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH;;;;;;;;;;;;;;;GAeG;AACH,SAAgB,eAAe,CAAC,CAAQ,EAAE,OAAO,GAAG,kBAAkB;IACrE,MAAM,IAAI,KAAK,CAAC,OAAO,CAAC,CAAC;AAC1B,CAAC;AAFD,0CAEC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\n/**\n * This function can be used to assert at compile time that a given value has type never.\n * One common usage is in the default case of a switch block,\n * to ensure that all cases are explicitly handled.\n *\n * Example:\n * ```typescript\n * const bool: true | false = ...;\n * switch(bool) {\n * case true: {...}\n * case false: {...}\n * default: unreachableCase(bool);\n * }\n * ```\n * @internal\n */\nexport function unreachableCase(_: never, message = \"Unreachable Case\"): never {\n\tthrow new Error(message);\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fluidframework/core-utils",
|
|
3
|
-
"version": "2.0.0-dev.7.4.0.
|
|
3
|
+
"version": "2.0.0-dev.7.4.0.221926",
|
|
4
4
|
"description": "Not intended for use outside the Fluid client repo.",
|
|
5
5
|
"homepage": "https://fluidframework.com",
|
|
6
6
|
"repository": {
|
|
@@ -35,12 +35,13 @@
|
|
|
35
35
|
"temp-directory": "nyc/.nyc_output"
|
|
36
36
|
},
|
|
37
37
|
"devDependencies": {
|
|
38
|
+
"@arethetypeswrong/cli": "^0.13.3",
|
|
38
39
|
"@fluid-tools/benchmark": "^0.47.0",
|
|
39
40
|
"@fluid-tools/build-cli": "^0.28.0",
|
|
40
41
|
"@fluidframework/build-common": "^2.0.3",
|
|
41
42
|
"@fluidframework/build-tools": "^0.28.0",
|
|
42
43
|
"@fluidframework/eslint-config-fluid": "^3.1.0",
|
|
43
|
-
"@fluidframework/mocha-test-setup": "2.0.0-dev.7.4.0.
|
|
44
|
+
"@fluidframework/mocha-test-setup": "2.0.0-dev.7.4.0.221926",
|
|
44
45
|
"@microsoft/api-extractor": "^7.38.3",
|
|
45
46
|
"@types/mocha": "^9.1.1",
|
|
46
47
|
"@types/node": "^18.19.0",
|
|
@@ -87,6 +88,7 @@
|
|
|
87
88
|
"build:docs": "fluid-build . --task api",
|
|
88
89
|
"build:esnext": "tsc --project ./tsconfig.esnext.json",
|
|
89
90
|
"build:test": "tsc --project ./src/test/tsconfig.json",
|
|
91
|
+
"check:are-the-types-wrong": "attw --pack",
|
|
90
92
|
"check:release-tags": "api-extractor run --local --config ./api-extractor-lint.json",
|
|
91
93
|
"ci:build:docs": "api-extractor run",
|
|
92
94
|
"clean": "rimraf --glob dist lib \"**/*.tsbuildinfo\" \"**/*.build.log\" _api-extractor-temp nyc",
|
package/src/promiseCache.ts
CHANGED
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
* - indefinite: entries don't expire and must be explicitly removed
|
|
9
9
|
* - absolute: entries expire after the given duration in MS, even if accessed multiple times in the mean time
|
|
10
10
|
* - sliding: entries expire after the given duration in MS of inactivity (i.e. get resets the clock)
|
|
11
|
-
* @
|
|
11
|
+
* @alpha
|
|
12
12
|
*/
|
|
13
13
|
export type PromiseCacheExpiry =
|
|
14
14
|
| {
|
|
@@ -21,7 +21,7 @@ export type PromiseCacheExpiry =
|
|
|
21
21
|
|
|
22
22
|
/**
|
|
23
23
|
* Options for configuring the {@link PromiseCache}
|
|
24
|
-
* @
|
|
24
|
+
* @alpha
|
|
25
25
|
*/
|
|
26
26
|
export interface PromiseCacheOptions {
|
|
27
27
|
/**
|
|
@@ -89,7 +89,7 @@ class GarbageCollector<TKey> {
|
|
|
89
89
|
/**
|
|
90
90
|
* A specialized cache for async work, allowing you to safely cache the promised result of some async work
|
|
91
91
|
* without fear of running it multiple times or losing track of errors.
|
|
92
|
-
* @
|
|
92
|
+
* @alpha
|
|
93
93
|
*/
|
|
94
94
|
export class PromiseCache<TKey, TResult> {
|
|
95
95
|
private readonly cache = new Map<TKey, Promise<TResult>>();
|