@fluidframework/core-utils 2.0.0-dev.5.3.2.178189 → 2.0.0-dev.6.4.0.191258
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/.eslintrc.js +1 -1
- package/.mocharc.js +1 -1
- package/CHANGELOG.md +24 -0
- package/README.md +32 -6
- package/dist/assert.d.ts +16 -0
- package/dist/assert.d.ts.map +1 -0
- package/dist/assert.js +24 -0
- package/dist/assert.js.map +1 -0
- package/dist/delay.d.ts +10 -0
- package/dist/delay.d.ts.map +1 -0
- package/dist/delay.js +14 -0
- package/dist/delay.js.map +1 -0
- package/dist/heap.d.ts +82 -0
- package/dist/heap.d.ts.map +1 -0
- package/dist/heap.js +139 -0
- package/dist/heap.js.map +1 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +16 -1
- package/dist/index.js.map +1 -1
- package/dist/promises.d.ts +37 -0
- package/dist/promises.d.ts.map +1 -0
- package/dist/promises.js +57 -0
- package/dist/promises.js.map +1 -0
- package/dist/timer.d.ts +105 -0
- package/dist/timer.d.ts.map +1 -0
- package/dist/timer.js +186 -0
- package/dist/timer.js.map +1 -0
- package/dist/unreachable.d.ts +21 -0
- package/dist/unreachable.d.ts.map +1 -0
- package/dist/unreachable.js +27 -0
- package/dist/unreachable.js.map +1 -0
- package/lib/assert.d.ts +16 -0
- package/lib/assert.d.ts.map +1 -0
- package/lib/assert.js +20 -0
- package/lib/assert.js.map +1 -0
- package/lib/delay.d.ts +10 -0
- package/lib/delay.d.ts.map +1 -0
- package/lib/delay.js +10 -0
- package/lib/delay.js.map +1 -0
- package/lib/heap.d.ts +82 -0
- package/lib/heap.d.ts.map +1 -0
- package/lib/heap.js +135 -0
- package/lib/heap.js.map +1 -0
- package/lib/index.d.ts +6 -0
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +6 -0
- package/lib/index.js.map +1 -1
- package/lib/promises.d.ts +37 -0
- package/lib/promises.d.ts.map +1 -0
- package/lib/promises.js +53 -0
- package/lib/promises.js.map +1 -0
- package/lib/timer.d.ts +105 -0
- package/lib/timer.d.ts.map +1 -0
- package/lib/timer.js +180 -0
- package/lib/timer.js.map +1 -0
- package/lib/unreachable.d.ts +21 -0
- package/lib/unreachable.d.ts.map +1 -0
- package/lib/unreachable.js +23 -0
- package/lib/unreachable.js.map +1 -0
- package/package.json +12 -15
- package/src/assert.ts +22 -0
- package/src/delay.ts +11 -0
- package/src/heap.ts +174 -0
- package/src/index.ts +13 -0
- package/src/promises.ts +60 -0
- package/src/timer.ts +279 -0
- package/src/unreachable.ts +23 -0
package/.eslintrc.js
CHANGED
|
@@ -19,7 +19,7 @@ module.exports = {
|
|
|
19
19
|
files: ["*.spec.ts", "src/test/**"],
|
|
20
20
|
rules: {
|
|
21
21
|
// Test files are run in node only so additional node libraries can be used.
|
|
22
|
-
"import/no-nodejs-modules": ["error", { allow: ["assert", "events"] }],
|
|
22
|
+
"import/no-nodejs-modules": ["error", { allow: ["assert", "events", "process"] }],
|
|
23
23
|
},
|
|
24
24
|
},
|
|
25
25
|
],
|
package/.mocharc.js
CHANGED
|
@@ -8,6 +8,6 @@
|
|
|
8
8
|
const getFluidTestMochaConfig = require("@fluidframework/mocha-test-setup/mocharc-common");
|
|
9
9
|
|
|
10
10
|
const packageDir = __dirname;
|
|
11
|
-
const config = getFluidTestMochaConfig(packageDir
|
|
11
|
+
const config = getFluidTestMochaConfig(packageDir);
|
|
12
12
|
config.spec = "dist/test";
|
|
13
13
|
module.exports = config;
|
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,29 @@
|
|
|
1
1
|
# @fluidframework/core-utils
|
|
2
2
|
|
|
3
|
+
## 2.0.0-internal.6.3.0
|
|
4
|
+
|
|
5
|
+
Dependency updates only.
|
|
6
|
+
|
|
7
|
+
## 2.0.0-internal.6.2.0
|
|
8
|
+
|
|
9
|
+
Dependency updates only.
|
|
10
|
+
|
|
11
|
+
## 2.0.0-internal.6.1.0
|
|
12
|
+
|
|
13
|
+
Dependency updates only.
|
|
14
|
+
|
|
15
|
+
## 2.0.0-internal.6.0.0
|
|
16
|
+
|
|
17
|
+
### Major Changes
|
|
18
|
+
|
|
19
|
+
- Upgraded typescript transpilation target to ES2020 [8abce8cdb4](https://github.com/microsoft/FluidFramework/commits/8abce8cdb4e2832fb6405fb44e393bef03d5648a)
|
|
20
|
+
|
|
21
|
+
Upgraded typescript transpilation target to ES2020. This is done in order to decrease the bundle sizes of Fluid Framework packages. This has provided size improvements across the board for ex. Loader, Driver, Runtime etc. Reduced bundle sizes helps to load lesser code in apps and hence also helps to improve the perf.If any app wants to target any older versions of browsers with which this target version is not compatible, then they can use packages like babel to transpile to a older target.
|
|
22
|
+
|
|
23
|
+
## 2.0.0-internal.5.4.0
|
|
24
|
+
|
|
25
|
+
Dependency updates only.
|
|
26
|
+
|
|
3
27
|
## 2.0.0-internal.5.3.0
|
|
4
28
|
|
|
5
29
|
Dependency updates only.
|
package/README.md
CHANGED
|
@@ -1,10 +1,35 @@
|
|
|
1
1
|
# @fluidframework/core-utils
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
This package is intended for sharing and promoting best-practice implementations of Fluid-agnostic utility functions
|
|
4
|
+
across packages in the Fluid Framework repo.
|
|
4
5
|
|
|
5
|
-
Use outside of the Fluid Framework
|
|
6
|
+
Use outside of the Fluid Framework repo is not supported or recommended.
|
|
6
7
|
|
|
7
|
-
|
|
8
|
+
## Adding code to this package
|
|
9
|
+
|
|
10
|
+
As a utility package, this package does not have a strong identity. This means that it's easy to become a "dumping
|
|
11
|
+
ground" for code that we think we should share but doesn't have an obvious home. We try to avoid dumping things into
|
|
12
|
+
utility packages, and this one is no exception.
|
|
13
|
+
|
|
14
|
+
New code should only be added to this package in rare circumstances. In most cases, the code would be better placed in a
|
|
15
|
+
package with a clear identity (e.g. an "events" package for shared event infrastructure) or not shared at all.
|
|
16
|
+
|
|
17
|
+
## Requirements
|
|
18
|
+
|
|
19
|
+
This package has important requirements for the code within it.
|
|
20
|
+
|
|
21
|
+
1. **Code in this package must have zero dependencies.** That is, it must not depend on other packages, even within the
|
|
22
|
+
Fluid Framework repo. `devDependencies` are OK.
|
|
23
|
+
1. **All exports must be designated `@internal`.** This code is intended for use within the Fluid Framework only.
|
|
24
|
+
1. This package should **only contain 'implementation' code, not type definitions.** This is the most flexible rule, and
|
|
25
|
+
there are some exceptions. If the type is _only_ necessary when using this package, then it is probably OK. However,
|
|
26
|
+
usually such types would be better placed in core-interfaces or in a package that corresponds to the purpose.
|
|
27
|
+
|
|
28
|
+
If you want to add code that does not meet these requirements, these other packages may be a better choice:
|
|
29
|
+
|
|
30
|
+
- **Types and interfaces** that are intended to be broadly shared across the client release group should be put in the
|
|
31
|
+
**core-interfaces** package.
|
|
32
|
+
- **Shared implementation code with dependencies** should be put in the **client-utils** package.
|
|
8
33
|
|
|
9
34
|
<!-- AUTO-GENERATED-CONTENT:START (README_DEPENDENCY_GUIDELINES_SECTION:includeHeading=TRUE) -->
|
|
10
35
|
|
|
@@ -17,9 +42,10 @@ When taking a dependency on a Fluid Framework library, we recommend using a `^`
|
|
|
17
42
|
While Fluid Framework libraries may use different ranges with interdependencies between other Fluid Framework libraries,
|
|
18
43
|
library consumers should always prefer `^`.
|
|
19
44
|
|
|
20
|
-
Note that when depending on a library version of the form 2.0.0-internal.x.y.z
|
|
21
|
-
|
|
22
|
-
|
|
45
|
+
Note that when depending on a library version of the form `2.0.0-internal.x.y.z`, called the Fluid internal version scheme,
|
|
46
|
+
you must use a `>= <` dependency range (such as `>=2.0.0-internal.x.y.z <2.0.0-internal.w.0.0` where `w` is `x+1`).
|
|
47
|
+
Standard `^` and `~` ranges will not work as expected.
|
|
48
|
+
See the [@fluid-tools/version-tools](https://github.com/microsoft/FluidFramework/blob/main/build-tools/packages/version-tools/README.md)
|
|
23
49
|
package for more information including tools to convert between version schemes.
|
|
24
50
|
|
|
25
51
|
<!-- prettier-ignore-end -->
|
package/dist/assert.d.ts
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* Copyright (c) Microsoft Corporation and contributors. All rights reserved.
|
|
3
|
+
* Licensed under the MIT License.
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* A browser friendly assert library.
|
|
7
|
+
* Use this instead of the 'assert' package, which has a big impact on bundle sizes.
|
|
8
|
+
* @param condition - The condition that should be true, if the condition is false an error will be thrown.
|
|
9
|
+
* Only use this API when `false` indicates a logic error in the problem and thus a bug that should be fixed.
|
|
10
|
+
* @param message - The message to include in the error when the condition does not hold.
|
|
11
|
+
* A number should not be specified manually: use a string.
|
|
12
|
+
* Before a release, policy-check should be run, which will convert any asserts still using strings to
|
|
13
|
+
* use numbered error codes instead.
|
|
14
|
+
*/
|
|
15
|
+
export declare function assert(condition: boolean, message: string | number): asserts condition;
|
|
16
|
+
//# sourceMappingURL=assert.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"assert.d.ts","sourceRoot":"","sources":["../src/assert.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH;;;;;;;;;GASG;AACH,wBAAgB,MAAM,CAAC,SAAS,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,GAAG,MAAM,GAAG,OAAO,CAAC,SAAS,CAMtF"}
|
package/dist/assert.js
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*!
|
|
3
|
+
* Copyright (c) Microsoft Corporation and contributors. All rights reserved.
|
|
4
|
+
* Licensed under the MIT License.
|
|
5
|
+
*/
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
exports.assert = void 0;
|
|
8
|
+
/**
|
|
9
|
+
* A browser friendly assert library.
|
|
10
|
+
* Use this instead of the 'assert' package, which has a big impact on bundle sizes.
|
|
11
|
+
* @param condition - The condition that should be true, if the condition is false an error will be thrown.
|
|
12
|
+
* Only use this API when `false` indicates a logic error in the problem and thus a bug that should be fixed.
|
|
13
|
+
* @param message - The message to include in the error when the condition does not hold.
|
|
14
|
+
* A number should not be specified manually: use a string.
|
|
15
|
+
* Before a release, policy-check should be run, which will convert any asserts still using strings to
|
|
16
|
+
* use numbered error codes instead.
|
|
17
|
+
*/
|
|
18
|
+
function assert(condition, message) {
|
|
19
|
+
if (!condition) {
|
|
20
|
+
throw new Error(typeof message === "number" ? `0x${message.toString(16).padStart(3, "0")}` : message);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
exports.assert = assert;
|
|
24
|
+
//# sourceMappingURL=assert.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"assert.js","sourceRoot":"","sources":["../src/assert.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH;;;;;;;;;GASG;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 */\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/dist/delay.d.ts
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* Copyright (c) Microsoft Corporation and contributors. All rights reserved.
|
|
3
|
+
* Licensed under the MIT License.
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* Returns a promise that resolves after `timeMs`.
|
|
7
|
+
* @param timeMs - Time in milliseconds to wait.
|
|
8
|
+
*/
|
|
9
|
+
export declare const delay: (timeMs: number) => Promise<void>;
|
|
10
|
+
//# sourceMappingURL=delay.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"delay.d.ts","sourceRoot":"","sources":["../src/delay.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH;;;GAGG;AACH,eAAO,MAAM,KAAK,WAAkB,MAAM,KAAG,QAAQ,IAAI,CACK,CAAC"}
|
package/dist/delay.js
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*!
|
|
3
|
+
* Copyright (c) Microsoft Corporation and contributors. All rights reserved.
|
|
4
|
+
* Licensed under the MIT License.
|
|
5
|
+
*/
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
exports.delay = void 0;
|
|
8
|
+
/**
|
|
9
|
+
* Returns a promise that resolves after `timeMs`.
|
|
10
|
+
* @param timeMs - Time in milliseconds to wait.
|
|
11
|
+
*/
|
|
12
|
+
const delay = async (timeMs) => new Promise((resolve) => setTimeout(() => resolve(), timeMs));
|
|
13
|
+
exports.delay = delay;
|
|
14
|
+
//# sourceMappingURL=delay.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"delay.js","sourceRoot":"","sources":["../src/delay.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH;;;GAGG;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 */\nexport const delay = async (timeMs: number): Promise<void> =>\n\tnew Promise((resolve) => setTimeout(() => resolve(), timeMs));\n"]}
|
package/dist/heap.d.ts
ADDED
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* Copyright (c) Microsoft Corporation and contributors. All rights reserved.
|
|
3
|
+
* Licensed under the MIT License.
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* Interface for a comparer.
|
|
7
|
+
*/
|
|
8
|
+
export interface IComparer<T> {
|
|
9
|
+
/**
|
|
10
|
+
* The minimum value of type T.
|
|
11
|
+
*/
|
|
12
|
+
min: T;
|
|
13
|
+
/**
|
|
14
|
+
* Compare the two value
|
|
15
|
+
*
|
|
16
|
+
* @returns 0 if the value is equal, negative number if a is smaller then b, positive number otherwise
|
|
17
|
+
*/
|
|
18
|
+
compare(a: T, b: T): number;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* A comparer for numbers.
|
|
22
|
+
*/
|
|
23
|
+
export declare const NumberComparer: IComparer<number>;
|
|
24
|
+
/**
|
|
25
|
+
* Interface to a node in {@link Heap}.
|
|
26
|
+
*/
|
|
27
|
+
export interface IHeapNode<T> {
|
|
28
|
+
value: T;
|
|
29
|
+
position: number;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Ordered {@link https://en.wikipedia.org/wiki/Heap_(data_structure) | Heap} data structure implementation.
|
|
33
|
+
*/
|
|
34
|
+
export declare class Heap<T> {
|
|
35
|
+
comp: IComparer<T>;
|
|
36
|
+
private L;
|
|
37
|
+
/**
|
|
38
|
+
* Creates an instance of `Heap` with comparer.
|
|
39
|
+
* @param comp - A comparer that specify how elements are ordered.
|
|
40
|
+
*/
|
|
41
|
+
constructor(comp: IComparer<T>);
|
|
42
|
+
/**
|
|
43
|
+
* Return the smallest element in the heap as determined by the order of the comparer
|
|
44
|
+
*
|
|
45
|
+
* @returns Heap node containing the smallest element
|
|
46
|
+
*/
|
|
47
|
+
peek(): IHeapNode<T>;
|
|
48
|
+
/**
|
|
49
|
+
* Get and remove the smallest element in the heap as determined by the order of the comparer
|
|
50
|
+
*
|
|
51
|
+
* @returns The smallest value in the heap
|
|
52
|
+
*/
|
|
53
|
+
get(): T;
|
|
54
|
+
/**
|
|
55
|
+
* Add a value to the heap
|
|
56
|
+
*
|
|
57
|
+
* @param x - value to add
|
|
58
|
+
* @returns The heap node that contains the value
|
|
59
|
+
*/
|
|
60
|
+
add(x: T): IHeapNode<T>;
|
|
61
|
+
/**
|
|
62
|
+
* Allows for the Heap to be updated after a node's value changes.
|
|
63
|
+
*/
|
|
64
|
+
update(node: IHeapNode<T>): void;
|
|
65
|
+
/**
|
|
66
|
+
* Removes the given node from the heap.
|
|
67
|
+
*
|
|
68
|
+
* @param node - The node to remove from the heap.
|
|
69
|
+
*/
|
|
70
|
+
remove(node: IHeapNode<T>): void;
|
|
71
|
+
/**
|
|
72
|
+
* Get the number of elements in the Heap.
|
|
73
|
+
*
|
|
74
|
+
* @returns The number of elements in the Heap.
|
|
75
|
+
*/
|
|
76
|
+
count(): number;
|
|
77
|
+
private fixup;
|
|
78
|
+
private isGreaterThanParent;
|
|
79
|
+
private fixdown;
|
|
80
|
+
private swap;
|
|
81
|
+
}
|
|
82
|
+
//# sourceMappingURL=heap.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"heap.d.ts","sourceRoot":"","sources":["../src/heap.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH;;GAEG;AACH,MAAM,WAAW,SAAS,CAAC,CAAC;IAC3B;;OAEG;IACH,GAAG,EAAE,CAAC,CAAC;IAEP;;;;OAIG;IACH,OAAO,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,GAAG,MAAM,CAAC;CAC5B;AAED;;GAEG;AACH,eAAO,MAAM,cAAc,EAAE,SAAS,CAAC,MAAM,CAW5C,CAAC;AAEF;;GAEG;AACH,MAAM,WAAW,SAAS,CAAC,CAAC;IAC3B,KAAK,EAAE,CAAC,CAAC;IACT,QAAQ,EAAE,MAAM,CAAC;CACjB;AAED;;GAEG;AACH,qBAAa,IAAI,CAAC,CAAC;IAOC,IAAI,EAAE,SAAS,CAAC,CAAC,CAAC;IANrC,OAAO,CAAC,CAAC,CAAiB;IAE1B;;;OAGG;gBACgB,IAAI,EAAE,SAAS,CAAC,CAAC,CAAC;IAIrC;;;;OAIG;IACI,IAAI,IAAI,SAAS,CAAC,CAAC,CAAC;IAI3B;;;;OAIG;IACI,GAAG,IAAI,CAAC;IAQf;;;;;OAKG;IACI,GAAG,CAAC,CAAC,EAAE,CAAC,GAAG,SAAS,CAAC,CAAC,CAAC;IAQ9B;;OAEG;IACI,MAAM,CAAC,IAAI,EAAE,SAAS,CAAC,CAAC,CAAC,GAAG,IAAI;IASvC;;;;OAIG;IACI,MAAM,CAAC,IAAI,EAAE,SAAS,CAAC,CAAC,CAAC,GAAG,IAAI;IAYvC;;;;OAIG;IACI,KAAK,IAAI,MAAM;IAItB,OAAO,CAAC,KAAK;IAUb,OAAO,CAAC,mBAAmB;IAK3B,OAAO,CAAC,OAAO;IAiBf,OAAO,CAAC,IAAI;CAOZ"}
|
package/dist/heap.js
ADDED
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*!
|
|
3
|
+
* Copyright (c) Microsoft Corporation and contributors. All rights reserved.
|
|
4
|
+
* Licensed under the MIT License.
|
|
5
|
+
*/
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
exports.Heap = exports.NumberComparer = void 0;
|
|
8
|
+
/**
|
|
9
|
+
* A comparer for numbers.
|
|
10
|
+
*/
|
|
11
|
+
exports.NumberComparer = {
|
|
12
|
+
/**
|
|
13
|
+
* The compare function for numbers.
|
|
14
|
+
* @returns The difference of the two numbers.
|
|
15
|
+
*/
|
|
16
|
+
compare: (a, b) => a - b,
|
|
17
|
+
/**
|
|
18
|
+
* The minimum value of a JavaScript number, which is `Number.MIN_VALUE`.
|
|
19
|
+
*/
|
|
20
|
+
min: Number.MIN_VALUE,
|
|
21
|
+
};
|
|
22
|
+
/**
|
|
23
|
+
* Ordered {@link https://en.wikipedia.org/wiki/Heap_(data_structure) | Heap} data structure implementation.
|
|
24
|
+
*/
|
|
25
|
+
class Heap {
|
|
26
|
+
/**
|
|
27
|
+
* Creates an instance of `Heap` with comparer.
|
|
28
|
+
* @param comp - A comparer that specify how elements are ordered.
|
|
29
|
+
*/
|
|
30
|
+
constructor(comp) {
|
|
31
|
+
this.comp = comp;
|
|
32
|
+
this.L = [{ value: comp.min, position: 0 }];
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Return the smallest element in the heap as determined by the order of the comparer
|
|
36
|
+
*
|
|
37
|
+
* @returns Heap node containing the smallest element
|
|
38
|
+
*/
|
|
39
|
+
peek() {
|
|
40
|
+
return this.L[1];
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Get and remove the smallest element in the heap as determined by the order of the comparer
|
|
44
|
+
*
|
|
45
|
+
* @returns The smallest value in the heap
|
|
46
|
+
*/
|
|
47
|
+
get() {
|
|
48
|
+
this.swap(1, this.count());
|
|
49
|
+
const x = this.L.pop();
|
|
50
|
+
this.fixdown(1);
|
|
51
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
52
|
+
return x.value;
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Add a value to the heap
|
|
56
|
+
*
|
|
57
|
+
* @param x - value to add
|
|
58
|
+
* @returns The heap node that contains the value
|
|
59
|
+
*/
|
|
60
|
+
add(x) {
|
|
61
|
+
const node = { value: x, position: this.L.length };
|
|
62
|
+
this.L.push(node);
|
|
63
|
+
this.fixup(this.count());
|
|
64
|
+
return node;
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Allows for the Heap to be updated after a node's value changes.
|
|
68
|
+
*/
|
|
69
|
+
update(node) {
|
|
70
|
+
const k = node.position;
|
|
71
|
+
if (this.isGreaterThanParent(k)) {
|
|
72
|
+
this.fixup(k);
|
|
73
|
+
}
|
|
74
|
+
else {
|
|
75
|
+
this.fixdown(k);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Removes the given node from the heap.
|
|
80
|
+
*
|
|
81
|
+
* @param node - The node to remove from the heap.
|
|
82
|
+
*/
|
|
83
|
+
remove(node) {
|
|
84
|
+
// Move the node we want to remove to the end of the array
|
|
85
|
+
const position = node.position;
|
|
86
|
+
this.swap(node.position, this.L.length - 1);
|
|
87
|
+
this.L.splice(this.L.length - 1);
|
|
88
|
+
// Update the swapped node assuming we didn't remove the end of the list
|
|
89
|
+
if (position !== this.L.length) {
|
|
90
|
+
this.update(this.L[position]);
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Get the number of elements in the Heap.
|
|
95
|
+
*
|
|
96
|
+
* @returns The number of elements in the Heap.
|
|
97
|
+
*/
|
|
98
|
+
count() {
|
|
99
|
+
return this.L.length - 1;
|
|
100
|
+
}
|
|
101
|
+
fixup(pos) {
|
|
102
|
+
let k = pos;
|
|
103
|
+
while (this.isGreaterThanParent(k)) {
|
|
104
|
+
// eslint-disable-next-line no-bitwise
|
|
105
|
+
const parent = k >> 1;
|
|
106
|
+
this.swap(k, parent);
|
|
107
|
+
k = parent;
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
isGreaterThanParent(k) {
|
|
111
|
+
// eslint-disable-next-line no-bitwise
|
|
112
|
+
return k > 1 && this.comp.compare(this.L[k >> 1].value, this.L[k].value) > 0;
|
|
113
|
+
}
|
|
114
|
+
fixdown(pos) {
|
|
115
|
+
let k = pos;
|
|
116
|
+
// eslint-disable-next-line no-bitwise
|
|
117
|
+
while (k << 1 <= this.count()) {
|
|
118
|
+
// eslint-disable-next-line no-bitwise
|
|
119
|
+
let j = k << 1;
|
|
120
|
+
if (j < this.count() && this.comp.compare(this.L[j].value, this.L[j + 1].value) > 0) {
|
|
121
|
+
j++;
|
|
122
|
+
}
|
|
123
|
+
if (this.comp.compare(this.L[k].value, this.L[j].value) <= 0) {
|
|
124
|
+
break;
|
|
125
|
+
}
|
|
126
|
+
this.swap(k, j);
|
|
127
|
+
k = j;
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
swap(k, j) {
|
|
131
|
+
const tmp = this.L[k];
|
|
132
|
+
this.L[k] = this.L[j];
|
|
133
|
+
this.L[k].position = k;
|
|
134
|
+
this.L[j] = tmp;
|
|
135
|
+
this.L[j].position = j;
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
exports.Heap = Heap;
|
|
139
|
+
//# sourceMappingURL=heap.js.map
|
package/dist/heap.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"heap.js","sourceRoot":"","sources":["../src/heap.ts"],"names":[],"mappings":"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","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 */\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 */\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 */\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 */\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(this.L.length - 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/dist/index.d.ts
CHANGED
|
@@ -2,7 +2,13 @@
|
|
|
2
2
|
* Copyright (c) Microsoft Corporation and contributors. All rights reserved.
|
|
3
3
|
* Licensed under the MIT License.
|
|
4
4
|
*/
|
|
5
|
+
export { assert } from "./assert";
|
|
5
6
|
export { compareArrays } from "./compare";
|
|
7
|
+
export { delay } from "./delay";
|
|
8
|
+
export { Heap, IComparer, IHeapNode, NumberComparer } from "./heap";
|
|
6
9
|
export { Lazy, LazyPromise } from "./lazy";
|
|
7
10
|
export { PromiseCache, PromiseCacheExpiry, PromiseCacheOptions } from "./promiseCache";
|
|
11
|
+
export { Deferred } from "./promises";
|
|
12
|
+
export { IPromiseTimer, IPromiseTimerResult, ITimer, PromiseTimer, setLongTimeout, Timer, } from "./timer";
|
|
13
|
+
export { unreachableCase } from "./unreachable";
|
|
8
14
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,aAAa,EAAE,MAAM,WAAW,CAAC;AAC1C,OAAO,EAAE,IAAI,EAAE,WAAW,EAAE,MAAM,QAAQ,CAAC;AAC3C,OAAO,EAAE,YAAY,EAAE,kBAAkB,EAAE,mBAAmB,EAAE,MAAM,gBAAgB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAClC,OAAO,EAAE,aAAa,EAAE,MAAM,WAAW,CAAC;AAC1C,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAChC,OAAO,EAAE,IAAI,EAAE,SAAS,EAAE,SAAS,EAAE,cAAc,EAAE,MAAM,QAAQ,CAAC;AACpE,OAAO,EAAE,IAAI,EAAE,WAAW,EAAE,MAAM,QAAQ,CAAC;AAC3C,OAAO,EAAE,YAAY,EAAE,kBAAkB,EAAE,mBAAmB,EAAE,MAAM,gBAAgB,CAAC;AACvF,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AACtC,OAAO,EACN,aAAa,EACb,mBAAmB,EACnB,MAAM,EACN,YAAY,EACZ,cAAc,EACd,KAAK,GACL,MAAM,SAAS,CAAC;AACjB,OAAO,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -4,12 +4,27 @@
|
|
|
4
4
|
* Licensed under the MIT License.
|
|
5
5
|
*/
|
|
6
6
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
-
exports.PromiseCache = exports.LazyPromise = exports.Lazy = exports.compareArrays = void 0;
|
|
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; } });
|
|
8
10
|
var compare_1 = require("./compare");
|
|
9
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; } });
|
|
10
17
|
var lazy_1 = require("./lazy");
|
|
11
18
|
Object.defineProperty(exports, "Lazy", { enumerable: true, get: function () { return lazy_1.Lazy; } });
|
|
12
19
|
Object.defineProperty(exports, "LazyPromise", { enumerable: true, get: function () { return lazy_1.LazyPromise; } });
|
|
13
20
|
var promiseCache_1 = require("./promiseCache");
|
|
14
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; } });
|
|
15
30
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH,qCAA0C;AAAjC,wGAAA,aAAa,OAAA;AACtB,+BAA2C;AAAlC,4FAAA,IAAI,OAAA;AAAE,mGAAA,WAAW,OAAA;AAC1B,+CAAuF;AAA9E,4GAAA,YAAY,OAAA","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nexport { compareArrays } from \"./compare\";\nexport { Lazy, LazyPromise } from \"./lazy\";\nexport { PromiseCache, PromiseCacheExpiry, PromiseCacheOptions } from \"./promiseCache\";\n"]}
|
|
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"]}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* Copyright (c) Microsoft Corporation and contributors. All rights reserved.
|
|
3
|
+
* Licensed under the MIT License.
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* A deferred creates a promise and the ability to resolve or reject it
|
|
7
|
+
*/
|
|
8
|
+
export declare class Deferred<T> {
|
|
9
|
+
private readonly p;
|
|
10
|
+
private res;
|
|
11
|
+
private rej;
|
|
12
|
+
private completed;
|
|
13
|
+
constructor();
|
|
14
|
+
/**
|
|
15
|
+
* Returns whether the underlying promise has been completed
|
|
16
|
+
*/
|
|
17
|
+
get isCompleted(): boolean;
|
|
18
|
+
/**
|
|
19
|
+
* Retrieves the underlying promise for the deferred
|
|
20
|
+
*
|
|
21
|
+
* @returns the underlying promise
|
|
22
|
+
*/
|
|
23
|
+
get promise(): Promise<T>;
|
|
24
|
+
/**
|
|
25
|
+
* Resolves the promise
|
|
26
|
+
*
|
|
27
|
+
* @param value - the value to resolve the promise with
|
|
28
|
+
*/
|
|
29
|
+
resolve(value: T | PromiseLike<T>): void;
|
|
30
|
+
/**
|
|
31
|
+
* Rejects the promise
|
|
32
|
+
*
|
|
33
|
+
* @param value - the value to reject the promise with
|
|
34
|
+
*/
|
|
35
|
+
reject(error: any): void;
|
|
36
|
+
}
|
|
37
|
+
//# sourceMappingURL=promises.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"promises.d.ts","sourceRoot":"","sources":["../src/promises.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH;;GAEG;AACH,qBAAa,QAAQ,CAAC,CAAC;IACtB,OAAO,CAAC,QAAQ,CAAC,CAAC,CAAa;IAC/B,OAAO,CAAC,GAAG,CAAoD;IAC/D,OAAO,CAAC,GAAG,CAAuC;IAClD,OAAO,CAAC,SAAS,CAAkB;;IAQnC;;OAEG;IACH,IAAW,WAAW,IAAI,OAAO,CAEhC;IAED;;;;OAIG;IACH,IAAW,OAAO,IAAI,OAAO,CAAC,CAAC,CAAC,CAE/B;IAED;;;;OAIG;IACI,OAAO,CAAC,KAAK,EAAE,CAAC,GAAG,WAAW,CAAC,CAAC,CAAC,GAAG,IAAI;IAO/C;;;;OAIG;IACI,MAAM,CAAC,KAAK,EAAE,GAAG,GAAG,IAAI;CAM/B"}
|
package/dist/promises.js
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*!
|
|
3
|
+
* Copyright (c) Microsoft Corporation and contributors. All rights reserved.
|
|
4
|
+
* Licensed under the MIT License.
|
|
5
|
+
*/
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
exports.Deferred = void 0;
|
|
8
|
+
/**
|
|
9
|
+
* A deferred creates a promise and the ability to resolve or reject it
|
|
10
|
+
*/
|
|
11
|
+
class Deferred {
|
|
12
|
+
constructor() {
|
|
13
|
+
this.completed = false;
|
|
14
|
+
this.p = new Promise((resolve, reject) => {
|
|
15
|
+
this.res = resolve;
|
|
16
|
+
this.rej = reject;
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Returns whether the underlying promise has been completed
|
|
21
|
+
*/
|
|
22
|
+
get isCompleted() {
|
|
23
|
+
return this.completed;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Retrieves the underlying promise for the deferred
|
|
27
|
+
*
|
|
28
|
+
* @returns the underlying promise
|
|
29
|
+
*/
|
|
30
|
+
get promise() {
|
|
31
|
+
return this.p;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Resolves the promise
|
|
35
|
+
*
|
|
36
|
+
* @param value - the value to resolve the promise with
|
|
37
|
+
*/
|
|
38
|
+
resolve(value) {
|
|
39
|
+
if (this.res !== undefined) {
|
|
40
|
+
this.completed = true;
|
|
41
|
+
this.res(value);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Rejects the promise
|
|
46
|
+
*
|
|
47
|
+
* @param value - the value to reject the promise with
|
|
48
|
+
*/
|
|
49
|
+
reject(error) {
|
|
50
|
+
if (this.rej !== undefined) {
|
|
51
|
+
this.completed = true;
|
|
52
|
+
this.rej(error);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
exports.Deferred = Deferred;
|
|
57
|
+
//# sourceMappingURL=promises.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"promises.js","sourceRoot":"","sources":["../src/promises.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH;;GAEG;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;IACI,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;AAnDD,4BAmDC","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 */\nexport class Deferred<T> {\n\tprivate readonly p: Promise<T>;\n\tprivate res: ((value: T | PromiseLike<T>) => void) | undefined;\n\tprivate rej: ((reason?: any) => void) | undefined;\n\tprivate completed: boolean = false;\n\n\tconstructor() {\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\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"]}
|