@thi.ng/rstream 8.3.20 → 8.4.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.
- package/CHANGELOG.md +7 -1
- package/README.md +2 -2
- package/api.d.ts +1 -1
- package/async.d.ts +17 -0
- package/async.js +57 -0
- package/index.d.ts +1 -0
- package/index.js +1 -0
- package/package.json +13 -10
package/CHANGELOG.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Change Log
|
|
2
2
|
|
|
3
|
-
- **Last updated**: 2024-04-
|
|
3
|
+
- **Last updated**: 2024-04-11T12:32:44Z
|
|
4
4
|
- **Generator**: [thi.ng/monopub](https://thi.ng/monopub)
|
|
5
5
|
|
|
6
6
|
All notable changes to this project will be documented in this file.
|
|
@@ -9,6 +9,12 @@ See [Conventional Commits](https://conventionalcommits.org/) for commit guidelin
|
|
|
9
9
|
**Note:** Unlisted _patch_ versions only involve non-code or otherwise excluded changes
|
|
10
10
|
and/or version bumps of transitive dependencies.
|
|
11
11
|
|
|
12
|
+
## [8.4.0](https://github.com/thi-ng/umbrella/tree/@thi.ng/rstream@8.4.0) (2024-04-11)
|
|
13
|
+
|
|
14
|
+
#### 🚀 Features
|
|
15
|
+
|
|
16
|
+
- add fromAsync() / asAsync() converters & tests ([df57056](https://github.com/thi-ng/umbrella/commit/df57056))
|
|
17
|
+
|
|
12
18
|
### [8.3.20](https://github.com/thi-ng/umbrella/tree/@thi.ng/rstream@8.3.20) (2024-04-08)
|
|
13
19
|
|
|
14
20
|
#### ♻️ Refactoring
|
package/README.md
CHANGED
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
[](https://mastodon.thi.ng/@toxi)
|
|
8
8
|
|
|
9
9
|
> [!NOTE]
|
|
10
|
-
> This is one of
|
|
10
|
+
> This is one of 192 standalone projects, maintained as part
|
|
11
11
|
> of the [@thi.ng/umbrella](https://github.com/thi-ng/umbrella/) monorepo
|
|
12
12
|
> and anti-framework.
|
|
13
13
|
>
|
|
@@ -214,7 +214,7 @@ For Node.js REPL:
|
|
|
214
214
|
const rs = await import("@thi.ng/rstream");
|
|
215
215
|
```
|
|
216
216
|
|
|
217
|
-
Package sizes (brotli'd, pre-treeshake): ESM: 6.
|
|
217
|
+
Package sizes (brotli'd, pre-treeshake): ESM: 6.32 KB
|
|
218
218
|
|
|
219
219
|
## Dependencies
|
|
220
220
|
|
package/api.d.ts
CHANGED
|
@@ -75,7 +75,7 @@ export interface TransformableOpts<A, B> extends CommonOpts, WithTransform<A, B>
|
|
|
75
75
|
export type ErrorHandler = Fn<any, boolean>;
|
|
76
76
|
export interface WithErrorHandler {
|
|
77
77
|
/**
|
|
78
|
-
* Optional error handler to use for this
|
|
78
|
+
* Optional error handler to use for this stream/subscription
|
|
79
79
|
*/
|
|
80
80
|
error: ErrorHandler;
|
|
81
81
|
}
|
package/async.d.ts
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { type ISubscription, type WithErrorHandlerOpts } from "./api.js";
|
|
2
|
+
/**
|
|
3
|
+
* Creates a new {@link stream} from given async iterable `src` and `opts`.
|
|
4
|
+
*
|
|
5
|
+
* @param src
|
|
6
|
+
* @param opts
|
|
7
|
+
*/
|
|
8
|
+
export declare const fromAsync: <T>(src: AsyncIterable<T>, opts?: Partial<WithErrorHandlerOpts>) => import("./stream.js").Stream<T>;
|
|
9
|
+
/**
|
|
10
|
+
* Reverse operation of {@link fromAsync}. Returns an async iterator which
|
|
11
|
+
* subscribes to given `src` sub and yields values as long as the `src` is
|
|
12
|
+
* intact.
|
|
13
|
+
*
|
|
14
|
+
* @param src
|
|
15
|
+
*/
|
|
16
|
+
export declare function asAsync<T>(src: ISubscription<any, T>): AsyncGenerator<Awaited<T>, void, unknown>;
|
|
17
|
+
//# sourceMappingURL=async.d.ts.map
|
package/async.js
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { SEMAPHORE } from "@thi.ng/api/api";
|
|
2
|
+
import { State } from "./api.js";
|
|
3
|
+
import { stream } from "./stream.js";
|
|
4
|
+
const fromAsync = (src, opts) => stream(($stream) => {
|
|
5
|
+
let active = true;
|
|
6
|
+
(async () => {
|
|
7
|
+
try {
|
|
8
|
+
for await (let x of src) {
|
|
9
|
+
if (!active)
|
|
10
|
+
return;
|
|
11
|
+
$stream.next(x);
|
|
12
|
+
}
|
|
13
|
+
$stream.done();
|
|
14
|
+
} catch (e) {
|
|
15
|
+
$stream.error(e);
|
|
16
|
+
}
|
|
17
|
+
})();
|
|
18
|
+
return () => active = false;
|
|
19
|
+
}, opts);
|
|
20
|
+
async function* asAsync(src) {
|
|
21
|
+
let resolve;
|
|
22
|
+
let initial;
|
|
23
|
+
const $newInitial = () => {
|
|
24
|
+
return initial = new Promise(($resolve) => {
|
|
25
|
+
resolve = $resolve;
|
|
26
|
+
});
|
|
27
|
+
};
|
|
28
|
+
const promises = [$newInitial()];
|
|
29
|
+
src.subscribe({
|
|
30
|
+
next(x) {
|
|
31
|
+
if (initial) {
|
|
32
|
+
resolve(x);
|
|
33
|
+
initial = void 0;
|
|
34
|
+
} else
|
|
35
|
+
promises.push(Promise.resolve(x));
|
|
36
|
+
},
|
|
37
|
+
done() {
|
|
38
|
+
if (initial) {
|
|
39
|
+
resolve(SEMAPHORE);
|
|
40
|
+
initial = void 0;
|
|
41
|
+
} else
|
|
42
|
+
promises.push(Promise.resolve(SEMAPHORE));
|
|
43
|
+
}
|
|
44
|
+
});
|
|
45
|
+
while (promises.length && src.getState() < State.ERROR) {
|
|
46
|
+
const res = await promises.shift();
|
|
47
|
+
if (res === SEMAPHORE)
|
|
48
|
+
break;
|
|
49
|
+
if (!promises.length)
|
|
50
|
+
promises[0] = $newInitial();
|
|
51
|
+
yield res;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
export {
|
|
55
|
+
asAsync,
|
|
56
|
+
fromAsync
|
|
57
|
+
};
|
package/index.d.ts
CHANGED
package/index.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@thi.ng/rstream",
|
|
3
|
-
"version": "8.
|
|
3
|
+
"version": "8.4.0",
|
|
4
4
|
"description": "Reactive streams & subscription primitives for constructing dataflow graphs / pipelines",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"module": "./index.js",
|
|
@@ -40,14 +40,14 @@
|
|
|
40
40
|
"tool:tangle": "../../node_modules/.bin/tangle src/**/*.ts"
|
|
41
41
|
},
|
|
42
42
|
"dependencies": {
|
|
43
|
-
"@thi.ng/api": "^8.10.
|
|
44
|
-
"@thi.ng/arrays": "^2.9.
|
|
45
|
-
"@thi.ng/associative": "^6.3.
|
|
46
|
-
"@thi.ng/atom": "^5.2.
|
|
47
|
-
"@thi.ng/checks": "^3.6.
|
|
48
|
-
"@thi.ng/errors": "^2.5.
|
|
49
|
-
"@thi.ng/logger": "^3.0.
|
|
50
|
-
"@thi.ng/transducers": "^9.0.
|
|
43
|
+
"@thi.ng/api": "^8.10.1",
|
|
44
|
+
"@thi.ng/arrays": "^2.9.3",
|
|
45
|
+
"@thi.ng/associative": "^6.3.56",
|
|
46
|
+
"@thi.ng/atom": "^5.2.43",
|
|
47
|
+
"@thi.ng/checks": "^3.6.1",
|
|
48
|
+
"@thi.ng/errors": "^2.5.4",
|
|
49
|
+
"@thi.ng/logger": "^3.0.9",
|
|
50
|
+
"@thi.ng/transducers": "^9.0.1"
|
|
51
51
|
},
|
|
52
52
|
"devDependencies": {
|
|
53
53
|
"@microsoft/api-extractor": "^7.43.0",
|
|
@@ -94,6 +94,9 @@
|
|
|
94
94
|
"./asidechain": {
|
|
95
95
|
"default": "./asidechain.js"
|
|
96
96
|
},
|
|
97
|
+
"./async": {
|
|
98
|
+
"default": "./async.js"
|
|
99
|
+
},
|
|
97
100
|
"./atom": {
|
|
98
101
|
"default": "./atom.js"
|
|
99
102
|
},
|
|
@@ -216,5 +219,5 @@
|
|
|
216
219
|
],
|
|
217
220
|
"year": 2017
|
|
218
221
|
},
|
|
219
|
-
"gitHead": "
|
|
222
|
+
"gitHead": "18a0c063a7b33d790e5bc2486c106f45f663ac28\n"
|
|
220
223
|
}
|