@fbltd/async 1.0.7 → 1.0.9
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 +36 -6
- package/package.json +7 -2
package/README.md
CHANGED
|
@@ -1,10 +1,37 @@
|
|
|
1
|
-
|
|
1
|
+
# Async tools
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
3
|
+
## delay
|
|
4
|
+
delay is a function that can be executed synchronous or asynchronous.
|
|
5
|
+
The behaviour depends on passed arguments:
|
|
6
|
+
```typescript
|
|
7
|
+
// Returns a promise - asynchrounous running in a non-blocking manner;
|
|
8
|
+
await delay(number);
|
|
9
|
+
|
|
10
|
+
// Returns nothing - synchrounous running in a blocking manner;
|
|
11
|
+
delay(number, true);
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
## getPromise
|
|
15
|
+
getPromise is a function that creates and returns promise, its fulfillment functions
|
|
16
|
+
and status flags.
|
|
17
|
+
Returned type is:
|
|
18
|
+
```typescript
|
|
19
|
+
type IPromiseConfiguration<T> = {
|
|
20
|
+
resolve(arg: T): void, // function that resolves promise
|
|
21
|
+
reject(err: Error): void, // function that rejects promise
|
|
22
|
+
promise: Promise<T>, // promise itself
|
|
23
|
+
readonly isPending: boolean, // promise status flag
|
|
24
|
+
readonly isFulfilled: boolean, // reverted promise status flag
|
|
25
|
+
}
|
|
26
|
+
```
|
|
27
|
+
There is no any management of passed data for resolving.
|
|
28
|
+
Returned promise is usual ES promise so it is impossible to fulfill promise twice.
|
|
6
29
|
|
|
7
|
-
|
|
30
|
+
## DependencyStream
|
|
31
|
+
### core
|
|
32
|
+
Implementation of reactive model leveraging native JavaScript async features like
|
|
33
|
+
Promises, (async) iterators and generators.
|
|
34
|
+
The version is 0.0.x so keep it in mind
|
|
8
35
|
|
|
9
36
|
```typescript
|
|
10
37
|
const counter = new DependencyStream<number>(0);
|
|
@@ -32,6 +59,8 @@ setInterval(() => {
|
|
|
32
59
|
}, 1000)
|
|
33
60
|
```
|
|
34
61
|
|
|
62
|
+
### Framework integrations
|
|
63
|
+
#### React
|
|
35
64
|
Of course, there is a React integration via useStream hook:
|
|
36
65
|
|
|
37
66
|
```typescript jsx
|
|
@@ -70,4 +99,5 @@ export const Counter: React.FC<ITest> = React.memo(({
|
|
|
70
99
|
})
|
|
71
100
|
```
|
|
72
101
|
|
|
73
|
-
|
|
102
|
+
## Disclaimer
|
|
103
|
+
Now this package is CommonJS module but should be an ESM.
|
package/package.json
CHANGED
|
@@ -1,7 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fbltd/async",
|
|
3
|
-
"version": "1.0.
|
|
4
|
-
"description": "
|
|
3
|
+
"version": "1.0.9",
|
|
4
|
+
"description": "Miscellaneous async utils",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"Reactivity",
|
|
7
|
+
"State Management",
|
|
8
|
+
"Async"
|
|
9
|
+
],
|
|
5
10
|
"exports": {
|
|
6
11
|
"require": "./dist/bin/index.js",
|
|
7
12
|
"import": "./dist/bin/index.js",
|