@fluidframework/core-utils 2.0.0-dev.7.4.0.217212 → 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 +5 -3
- 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
|