watchable-promise 1.0.0 → 2.0.0

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.
Files changed (2) hide show
  1. package/README.md +27 -18
  2. package/package.json +3 -3
package/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # watchable-promise
2
2
 
3
- A Promise whose status you can read
3
+ A Promise whose state and value you can read
4
4
 
5
5
  ## Installation
6
6
 
@@ -13,12 +13,20 @@ npm install watchable-promise
13
13
  - Directly create a `WatchablePromise` instance:
14
14
 
15
15
  ```javascript
16
- import WatchablePromise from 'watchable-promise';
16
+ import WatchablePromise from "watchable-promise";
17
17
 
18
- const p = new WatchablePromise();
18
+ const p = new WatchablePromise(resolve => setTimeout(() => resolve("foo"), 100));
19
19
 
20
- console.log(p.status); // pending
20
+ console.log(p.state); // pending
21
21
  console.log(p.settled); // false
22
+ console.log(p.value); // undefined
23
+
24
+ const val = await p;
25
+
26
+ console.log(val) // "foo"
27
+ console.log(p.state); // fulfilled
28
+ console.log(p.settled); // true
29
+ console.log(p.value); // "foo"
22
30
  ```
23
31
 
24
32
  - Using an existing `Promise` instance:
@@ -26,17 +34,19 @@ npm install watchable-promise
26
34
  ```javascript
27
35
  import WatchablePromise from 'watchable-promise';
28
36
 
29
- const existingPromise = new Promise(resolve => setTimeout(() => resolve('foo'), 100));
37
+ const existingPromise = new Promise(resolve => setTimeout(() => resolve("foo"), 100));
30
38
  const p = WatchablePromise.from(existingPromise);
31
39
 
32
- console.log(p.status); // pending
40
+ console.log(p.state); // pending
33
41
  console.log(p.settled); // false
42
+ console.log(p.value); // undefined
43
+
44
+ const val = await p;
34
45
 
35
- p.then(val => {
36
- console.log(val) // 'bar'
37
- console.log(p.status); // fulfilled
38
- console.log(p.settled); // true
39
- });
46
+ console.log(val) // "foo"
47
+ console.log(p.state); // fulfilled
48
+ console.log(p.settled); // true
49
+ console.log(p.value); // "foo"
40
50
  ```
41
51
 
42
52
  - Using `WatchablePromise.withResolvers()`:
@@ -46,16 +56,15 @@ npm install watchable-promise
46
56
 
47
57
  const { promise, resolve, reject } = WatchablePromise.withResolvers();
48
58
 
49
- console.log(promise.status); // pending
59
+ console.log(promise.state); // pending
50
60
  console.log(promise.settled); // false
61
+ console.log(promise.value); // undefined
51
62
 
52
- resolve('bar');
63
+ await resolve("foo");
53
64
 
54
- promise.then(val => {
55
- console.log(val) // 'bar'
56
- console.log(promise.status); // fulfilled
57
- console.log(promise.settled); // true
58
- });
65
+ console.log(promise.state); // fulfilled
66
+ console.log(promise.settled); // true
67
+ console.log(promise.value); // "foo"
59
68
  ```
60
69
 
61
70
  ## License
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "watchable-promise",
3
- "version": "1.0.0",
4
- "description": "A Promise whose status you can read",
3
+ "version": "2.0.0",
4
+ "description": "A Promise whose state and value you can read",
5
5
  "type": "module",
6
6
  "module": "dist/index.js",
7
7
  "types": "dist/index.d.ts",
@@ -30,7 +30,7 @@
30
30
  },
31
31
  "keywords": [
32
32
  "promises",
33
- "status",
33
+ "state",
34
34
  "watchable"
35
35
  ],
36
36
  "author": {