@endo/promise-kit 1.1.1 → 1.1.3
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/README.md +70 -1
- package/package.json +13 -13
- package/src/memo-race.d.ts.map +1 -1
- package/src/promise-executor-kit.d.ts +1 -1
- package/src/promise-executor-kit.d.ts.map +1 -1
- package/src/types.d.ts.map +1 -1
package/README.md
CHANGED
|
@@ -1,3 +1,72 @@
|
|
|
1
1
|
# Promise Kit
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
The promise-kit package provides a simple abstraction for creating and managing a promise. It exports, `makePromiseKit` which is a utility function used to create a Promise and its associated resolver and rejector functions. This is particularly useful in asynchronous programming, where you might need to create a promise and resolve or reject it at a later point in time.
|
|
4
|
+
Note that this serves as a "ponyfill" for `Promise.withResolvers`, making certain accommodations to ensure that the resulting promises can pipeline messages through `@endo/eventual-send`.
|
|
5
|
+
|
|
6
|
+
## Usage
|
|
7
|
+
|
|
8
|
+
Here’s an example of how `makePromiseKit` might be used in an Agoric smart contract or JavaScript program:
|
|
9
|
+
|
|
10
|
+
### Basic Example
|
|
11
|
+
|
|
12
|
+
```javascript
|
|
13
|
+
import { makePromiseKit } from '@endo/promise-kit';
|
|
14
|
+
|
|
15
|
+
function asyncOperation() {
|
|
16
|
+
|
|
17
|
+
const { promise, resolve, reject } = makePromiseKit();
|
|
18
|
+
setTimeout(() => {
|
|
19
|
+
const success = true; // Simulating success or failure
|
|
20
|
+
if (success) {
|
|
21
|
+
resolve("Operation successful!");
|
|
22
|
+
} else {
|
|
23
|
+
reject("Operation failed!");
|
|
24
|
+
}
|
|
25
|
+
}, 2000);
|
|
26
|
+
|
|
27
|
+
return promise;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
async function handleAsyncOperation() {
|
|
31
|
+
try {
|
|
32
|
+
const result = await asyncOperation();
|
|
33
|
+
console.log(result); // "Operation successful!"
|
|
34
|
+
} catch (error) {
|
|
35
|
+
console.error(error); // "Operation failed!"
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
handleAsyncOperation();
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
### Creating Multiple Promise Kits
|
|
43
|
+
|
|
44
|
+
You can create multiple promise kits for managing various asynchronous tasks.
|
|
45
|
+
|
|
46
|
+
```javascript
|
|
47
|
+
const kit1 = makePromiseKit();
|
|
48
|
+
const kit2 = makePromiseKit();
|
|
49
|
+
|
|
50
|
+
kit1.promise.then(value => console.log('Kit 1 resolved with:', value));
|
|
51
|
+
kit2.promise.then(value => console.log('Kit 2 resolved with:', value));
|
|
52
|
+
|
|
53
|
+
kit1.resolve('First success');
|
|
54
|
+
kit2.resolve('Second success');
|
|
55
|
+
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
## API
|
|
59
|
+
|
|
60
|
+
### `makePromiseKit()`
|
|
61
|
+
Creates a new promise kit.
|
|
62
|
+
|
|
63
|
+
**Returns**
|
|
64
|
+
- **`promise`**: The promise object.
|
|
65
|
+
- **`resolve`**: The resolve function for the promise.
|
|
66
|
+
- **`reject`**: The reject function for the promise.
|
|
67
|
+
|
|
68
|
+
## Links
|
|
69
|
+
[Repository](https://github.com/endojs/endo/tree/master/packages/promise-kit)
|
|
70
|
+
|
|
71
|
+
## License
|
|
72
|
+
This package is licensed under the Apache-2.0 License.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@endo/promise-kit",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.3",
|
|
4
4
|
"description": "Helper for making promises",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"promise"
|
|
@@ -26,8 +26,8 @@
|
|
|
26
26
|
},
|
|
27
27
|
"scripts": {
|
|
28
28
|
"build": "exit 0",
|
|
29
|
-
"
|
|
30
|
-
"
|
|
29
|
+
"prepack": "tsc --build tsconfig.build.json",
|
|
30
|
+
"postpack": "git clean -f '*.d.ts*'",
|
|
31
31
|
"cover": "c8 ava",
|
|
32
32
|
"lint": "yarn lint:types && yarn lint:eslint",
|
|
33
33
|
"lint-check": "yarn lint",
|
|
@@ -38,20 +38,19 @@
|
|
|
38
38
|
"test:xs": "exit 0"
|
|
39
39
|
},
|
|
40
40
|
"dependencies": {
|
|
41
|
-
"ses": "^1.
|
|
41
|
+
"ses": "^1.6.0"
|
|
42
42
|
},
|
|
43
43
|
"devDependencies": {
|
|
44
|
-
"
|
|
45
|
-
"
|
|
46
|
-
"babel-eslint": "^10.0.3",
|
|
44
|
+
"ava": "^6.1.3",
|
|
45
|
+
"babel-eslint": "^10.1.0",
|
|
47
46
|
"c8": "^7.14.0",
|
|
48
47
|
"eslint": "^8.57.0",
|
|
49
48
|
"eslint-config-airbnb-base": "^15.0.0",
|
|
50
49
|
"eslint-config-prettier": "^9.1.0",
|
|
51
|
-
"eslint-plugin-eslint-comments": "^3.
|
|
52
|
-
"eslint-plugin-import": "^2.29.
|
|
53
|
-
"prettier": "^3.
|
|
54
|
-
"typescript": "
|
|
50
|
+
"eslint-plugin-eslint-comments": "^3.2.0",
|
|
51
|
+
"eslint-plugin-import": "^2.29.1",
|
|
52
|
+
"prettier": "^3.2.5",
|
|
53
|
+
"typescript": "5.5.2"
|
|
55
54
|
},
|
|
56
55
|
"files": [
|
|
57
56
|
"LICENSE*",
|
|
@@ -70,7 +69,8 @@
|
|
|
70
69
|
},
|
|
71
70
|
"ava": {
|
|
72
71
|
"files": [
|
|
73
|
-
"test/**/test
|
|
72
|
+
"test/**/test-*.*",
|
|
73
|
+
"test/**/*.test.*"
|
|
74
74
|
],
|
|
75
75
|
"timeout": "2m"
|
|
76
76
|
},
|
|
@@ -80,5 +80,5 @@
|
|
|
80
80
|
"typeCoverage": {
|
|
81
81
|
"atLeast": 90.9
|
|
82
82
|
},
|
|
83
|
-
"gitHead": "
|
|
83
|
+
"gitHead": "681b813ccb1fa177905dabf2ed3f5f248cb33ce7"
|
|
84
84
|
}
|
package/src/memo-race.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"memo-race.d.ts","sourceRoot":"","sources":["memo-race.js"],"names":[],"mappings":";
|
|
1
|
+
{"version":3,"file":"memo-race.d.ts","sourceRoot":"","sources":["memo-race.js"],"names":[],"mappings":";qBAiCc,CAAC;aAED,CAAC,KAAK,CAAC,EAAE,OAAO,YAAY,EAAE,IAAI,CAAC,CAAC,CAAC,KAAM,IAAI;YAC/C,CAAC,GAAG,CAAC,EAAE,GAAG,KAAM,IAAI;;gCAIpB,KAAK,GACb;IAAC,OAAO,EAAE,KAAK,CAAC;IAAC,SAAS,EAAE,GAAG,CAAC,QAAQ,CAAC,CAAA;CAAC,GAC1C;IAAC,OAAO,EAAE,IAAI,CAAC;IAAC,SAAS,CAAC,EAAE,SAAS,CAAA;CAAC;AAgE1C;;;;;;;;;;;;GAYG;AACH,sBANa,CAAC,EACqB,CAAC,SAAtB,kBAAmB,wCAEtB,QAAQ,CAAC,CAAC,CAAC,GACT,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,CAgC/B"}
|
|
@@ -4,5 +4,5 @@ export function makeReleasingExecutorKit<T>(): Pick<import("./types.js").Promise
|
|
|
4
4
|
/**
|
|
5
5
|
* The promise executor
|
|
6
6
|
*/
|
|
7
|
-
export type PromiseExecutor<T> = (resolve: (value: import(
|
|
7
|
+
export type PromiseExecutor<T> = (resolve: (value: import("./types.js").ERef<T>) => void, reject: (reason: any) => void) => any;
|
|
8
8
|
//# sourceMappingURL=promise-executor-kit.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"promise-executor-kit.d.ts","sourceRoot":"","sources":["promise-executor-kit.js"],"names":[],"mappings":"AAiBO,
|
|
1
|
+
{"version":3,"file":"promise-executor-kit.d.ts","sourceRoot":"","sources":["promise-executor-kit.js"],"names":[],"mappings":"AAiBO,yCAHM,CAAC,KACD,IAAI,CAAC,OAAO,YAAY,EAAE,UAAU,CAAC,CAAC,CAAC,EAAE,SAAS,GAAG,QAAQ,CAAC,GAAG;IAAE,QAAQ,EAAE,eAAe,CAAC,CAAC,CAAC,CAAA;CAAC,CAqC5G;;;;4BAjDY,CAAC,cAEH,CAAC,KAAK,EAAE,OAAO,YAAY,EAAE,IAAI,CAAC,CAAC,CAAC,KAAK,IAAI,UAC7C,CAAC,MAAM,EAAE,GAAG,KAAK,IAAI"}
|
package/src/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["types.js"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["types.js"],"names":[],"mappings":";;;uBACa,CAAC;aAEA,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC,CAAC,KAAK,IAAI;YACxB,CAAC,MAAM,EAAE,GAAG,KAAK,IAAI;aACrB,OAAO,CAAC,CAAC,CAAC;;;;;0BAMX,CAAC,IACD,UAAU,CAAC,CAAC,CAAC;;;;;;;iBAIb,CAAC,IACD,CAAC,GAAG,WAAW,CAAC,CAAC,CAAC"}
|