@thi.ng/transducers-async 0.2.4 → 0.2.5
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 +1 -1
- package/README.md +1 -1
- package/as-async.js +1 -2
- package/cat.js +1 -2
- package/merge.js +3 -6
- package/mult.js +6 -12
- package/package.json +12 -12
- package/partition.js +1 -2
- package/pubsub.js +4 -8
- package/push.js +1 -2
- package/raf.js +3 -6
- package/sidechain.js +4 -8
- package/source.js +6 -12
- package/sync.js +6 -12
- package/zip.js +1 -2
package/CHANGELOG.md
CHANGED
package/README.md
CHANGED
package/as-async.js
CHANGED
package/cat.js
CHANGED
package/merge.js
CHANGED
|
@@ -3,10 +3,8 @@ async function* merge(src) {
|
|
|
3
3
|
let n = iters.length;
|
|
4
4
|
const $remove = (id) => {
|
|
5
5
|
iters.splice(id, 1);
|
|
6
|
-
if (!--n)
|
|
7
|
-
|
|
8
|
-
for (let i = id; i < n; i++)
|
|
9
|
-
iters[i].id--;
|
|
6
|
+
if (!--n) return true;
|
|
7
|
+
for (let i = id; i < n; i++) iters[i].id--;
|
|
10
8
|
};
|
|
11
9
|
const promises = iters.map(
|
|
12
10
|
(iter) => iter.iter.next().then((res) => ({ iter, res }))
|
|
@@ -15,8 +13,7 @@ async function* merge(src) {
|
|
|
15
13
|
const { iter, res } = await Promise.race(promises);
|
|
16
14
|
if (res.done) {
|
|
17
15
|
promises.splice(iter.id, 1);
|
|
18
|
-
if ($remove(iter.id))
|
|
19
|
-
return;
|
|
16
|
+
if ($remove(iter.id)) return;
|
|
20
17
|
} else {
|
|
21
18
|
yield res.value;
|
|
22
19
|
promises[iter.id] = iter.iter.next().then((res2) => ({ res: res2, iter }));
|
package/mult.js
CHANGED
|
@@ -18,16 +18,12 @@ class Mult {
|
|
|
18
18
|
this.isActive = true;
|
|
19
19
|
(async () => {
|
|
20
20
|
for await (let val of this.src) {
|
|
21
|
-
for (let s of this.subs)
|
|
22
|
-
|
|
23
|
-
if (
|
|
24
|
-
this.subs.length = 0;
|
|
25
|
-
if (!this.subs.length)
|
|
26
|
-
break;
|
|
21
|
+
for (let s of this.subs) s.resolve(val);
|
|
22
|
+
if (val === void 0) this.subs.length = 0;
|
|
23
|
+
if (!this.subs.length) break;
|
|
27
24
|
await Promise.all(this.subs.map((x) => x.notifyP));
|
|
28
25
|
}
|
|
29
|
-
for (let s of this.subs)
|
|
30
|
-
s.resolve(void 0);
|
|
26
|
+
for (let s of this.subs) s.resolve(void 0);
|
|
31
27
|
this.subs.length = 0;
|
|
32
28
|
this.isActive = false;
|
|
33
29
|
})();
|
|
@@ -60,13 +56,11 @@ class MSub {
|
|
|
60
56
|
this.$await();
|
|
61
57
|
}
|
|
62
58
|
async *[Symbol.asyncIterator]() {
|
|
63
|
-
if (this.active)
|
|
64
|
-
illegalState("multiple consumers unsupported");
|
|
59
|
+
if (this.active) illegalState("multiple consumers unsupported");
|
|
65
60
|
this.active = true;
|
|
66
61
|
while (true) {
|
|
67
62
|
const res = await this.valueP;
|
|
68
|
-
if (res === void 0)
|
|
69
|
-
break;
|
|
63
|
+
if (res === void 0) break;
|
|
70
64
|
yield res;
|
|
71
65
|
this.notify();
|
|
72
66
|
this.$await();
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@thi.ng/transducers-async",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.5",
|
|
4
4
|
"description": "Async versions of various highly composable transducers, reducers and iterators",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"module": "./index.js",
|
|
@@ -36,18 +36,18 @@
|
|
|
36
36
|
"tool:tangle": "../../node_modules/.bin/tangle src/**/*.ts"
|
|
37
37
|
},
|
|
38
38
|
"dependencies": {
|
|
39
|
-
"@thi.ng/api": "^8.11.
|
|
40
|
-
"@thi.ng/buffers": "^0.1.
|
|
41
|
-
"@thi.ng/checks": "^3.6.
|
|
42
|
-
"@thi.ng/compose": "^3.0.
|
|
43
|
-
"@thi.ng/errors": "^2.5.
|
|
44
|
-
"@thi.ng/transducers": "^9.0.
|
|
39
|
+
"@thi.ng/api": "^8.11.2",
|
|
40
|
+
"@thi.ng/buffers": "^0.1.3",
|
|
41
|
+
"@thi.ng/checks": "^3.6.4",
|
|
42
|
+
"@thi.ng/compose": "^3.0.4",
|
|
43
|
+
"@thi.ng/errors": "^2.5.7",
|
|
44
|
+
"@thi.ng/transducers": "^9.0.5"
|
|
45
45
|
},
|
|
46
46
|
"devDependencies": {
|
|
47
|
-
"@microsoft/api-extractor": "^7.43.
|
|
48
|
-
"esbuild": "^0.
|
|
49
|
-
"typedoc": "^0.25.
|
|
50
|
-
"typescript": "^5.4.
|
|
47
|
+
"@microsoft/api-extractor": "^7.43.2",
|
|
48
|
+
"esbuild": "^0.21.1",
|
|
49
|
+
"typedoc": "^0.25.13",
|
|
50
|
+
"typescript": "^5.4.5"
|
|
51
51
|
},
|
|
52
52
|
"keywords": [
|
|
53
53
|
"async",
|
|
@@ -204,5 +204,5 @@
|
|
|
204
204
|
"status": "alpha",
|
|
205
205
|
"year": 2018
|
|
206
206
|
},
|
|
207
|
-
"gitHead": "
|
|
207
|
+
"gitHead": "df34b4a9e650cc7323575356de207d78933bdcf3\n"
|
|
208
208
|
}
|
package/partition.js
CHANGED
|
@@ -3,8 +3,7 @@ import { unreduced } from "@thi.ng/transducers/reduced";
|
|
|
3
3
|
import { __iter, iterator } from "./iterator.js";
|
|
4
4
|
function partition(...args) {
|
|
5
5
|
const iter = __iter(partition, args, iterator);
|
|
6
|
-
if (iter)
|
|
7
|
-
return iter;
|
|
6
|
+
if (iter) return iter;
|
|
8
7
|
let size = args[0], all, step;
|
|
9
8
|
if (isNumber(args[1])) {
|
|
10
9
|
step = args[1];
|
package/pubsub.js
CHANGED
|
@@ -34,8 +34,7 @@ class PubSub {
|
|
|
34
34
|
*/
|
|
35
35
|
unsubscribeTopic(id, sub) {
|
|
36
36
|
const subs = this.topics.get(id);
|
|
37
|
-
if (!subs)
|
|
38
|
-
return false;
|
|
37
|
+
if (!subs) return false;
|
|
39
38
|
const idx = subs.findIndex((x) => x === sub) ?? -1;
|
|
40
39
|
if (idx >= 0) {
|
|
41
40
|
subs.splice(idx, 1);
|
|
@@ -48,15 +47,12 @@ class PubSub {
|
|
|
48
47
|
for await (let val of this.src) {
|
|
49
48
|
const topic = this.topicFn(val);
|
|
50
49
|
const subs = this.topics.get(topic);
|
|
51
|
-
if (!(subs && subs.length))
|
|
52
|
-
|
|
53
|
-
for (let s of subs)
|
|
54
|
-
s.resolve(val);
|
|
50
|
+
if (!(subs && subs.length)) continue;
|
|
51
|
+
for (let s of subs) s.resolve(val);
|
|
55
52
|
await Promise.all(subs.map((x) => x.notifyP));
|
|
56
53
|
}
|
|
57
54
|
for (let subs of this.topics.values()) {
|
|
58
|
-
for (let s of subs)
|
|
59
|
-
s.resolve(void 0);
|
|
55
|
+
for (let s of subs) s.resolve(void 0);
|
|
60
56
|
}
|
|
61
57
|
this.topics.clear();
|
|
62
58
|
this.isActive = false;
|
package/push.js
CHANGED
package/raf.js
CHANGED
|
@@ -9,13 +9,10 @@ const raf = (opts) => {
|
|
|
9
9
|
gen.write(void 0);
|
|
10
10
|
};
|
|
11
11
|
const update = (t) => {
|
|
12
|
-
if (isClosed)
|
|
13
|
-
return;
|
|
12
|
+
if (isClosed) return;
|
|
14
13
|
if (opts?.timestamp) {
|
|
15
|
-
if (t0 === true)
|
|
16
|
-
|
|
17
|
-
if (t0)
|
|
18
|
-
t -= t0;
|
|
14
|
+
if (t0 === true) t0 = t;
|
|
15
|
+
if (t0) t -= t0;
|
|
19
16
|
} else {
|
|
20
17
|
t = frame++;
|
|
21
18
|
}
|
package/sidechain.js
CHANGED
|
@@ -9,12 +9,10 @@ async function* sidechain(src, side, opts) {
|
|
|
9
9
|
let buf = [];
|
|
10
10
|
while (true) {
|
|
11
11
|
const [res, side2] = await Promise.race(promises);
|
|
12
|
-
if (res.done)
|
|
13
|
-
return;
|
|
12
|
+
if (res.done) return;
|
|
14
13
|
if (side2) {
|
|
15
14
|
promises[1] = $side.next().then((res2) => [res2, true]);
|
|
16
|
-
if (!buf.length)
|
|
17
|
-
continue;
|
|
15
|
+
if (!buf.length) continue;
|
|
18
16
|
if (lastOnly) {
|
|
19
17
|
yield buf[0];
|
|
20
18
|
buf.length = 0;
|
|
@@ -24,10 +22,8 @@ async function* sidechain(src, side, opts) {
|
|
|
24
22
|
}
|
|
25
23
|
} else {
|
|
26
24
|
promises[0] = $iter.next().then((res2) => [res2]);
|
|
27
|
-
if (lastOnly)
|
|
28
|
-
|
|
29
|
-
else
|
|
30
|
-
buf.push(res.value);
|
|
25
|
+
if (lastOnly) buf[0] = res.value;
|
|
26
|
+
else buf.push(res.value);
|
|
31
27
|
}
|
|
32
28
|
}
|
|
33
29
|
}
|
package/source.js
CHANGED
|
@@ -17,33 +17,27 @@ const source = (initial, buffer = 1) => {
|
|
|
17
17
|
while (true) {
|
|
18
18
|
const val = await promise;
|
|
19
19
|
last = val;
|
|
20
|
-
if (val === void 0)
|
|
21
|
-
break;
|
|
20
|
+
if (val === void 0) break;
|
|
22
21
|
yield val;
|
|
23
22
|
newPromise();
|
|
24
|
-
if (queue.readable())
|
|
25
|
-
resolve(queue.read());
|
|
23
|
+
if (queue.readable()) resolve(queue.read());
|
|
26
24
|
}
|
|
27
25
|
state = 2;
|
|
28
26
|
}();
|
|
29
27
|
gen.write = (x) => {
|
|
30
|
-
if (state > 0)
|
|
31
|
-
return;
|
|
28
|
+
if (state > 0) return;
|
|
32
29
|
if (resolve) {
|
|
33
30
|
resolve(x);
|
|
34
31
|
resolve = void 0;
|
|
35
32
|
} else if (queue.writable()) {
|
|
36
33
|
queue.write(x);
|
|
37
|
-
if (x === void 0)
|
|
38
|
-
|
|
39
|
-
} else
|
|
40
|
-
illegalState("buffer overflow");
|
|
34
|
+
if (x === void 0) state = 1;
|
|
35
|
+
} else illegalState("buffer overflow");
|
|
41
36
|
};
|
|
42
37
|
gen.update = (fn, ...args) => gen.write(fn(last, ...args));
|
|
43
38
|
gen.close = () => gen.write(void 0);
|
|
44
39
|
gen.deref = () => last;
|
|
45
|
-
if (initial !== void 0)
|
|
46
|
-
gen.write(initial);
|
|
40
|
+
if (initial !== void 0) gen.write(initial);
|
|
47
41
|
return gen;
|
|
48
42
|
};
|
|
49
43
|
export {
|
package/sync.js
CHANGED
|
@@ -7,20 +7,16 @@ async function* sync(src, opts) {
|
|
|
7
7
|
let n = iters.length;
|
|
8
8
|
const $remove = (id) => {
|
|
9
9
|
iters.splice(id, 1);
|
|
10
|
-
if (!--n)
|
|
11
|
-
|
|
12
|
-
for (let i = id; i < n; i++)
|
|
13
|
-
iters[i].id--;
|
|
10
|
+
if (!--n) return true;
|
|
11
|
+
for (let i = id; i < n; i++) iters[i].id--;
|
|
14
12
|
};
|
|
15
13
|
const $initial = async () => {
|
|
16
14
|
const res = await Promise.all(iters.map(({ iter }) => iter.next()));
|
|
17
15
|
for (let i = 0; i < n; ) {
|
|
18
16
|
if (res[i].done) {
|
|
19
17
|
res.splice(i, 1);
|
|
20
|
-
if ($remove(i))
|
|
21
|
-
|
|
22
|
-
} else
|
|
23
|
-
i++;
|
|
18
|
+
if ($remove(i)) return;
|
|
19
|
+
} else i++;
|
|
24
20
|
}
|
|
25
21
|
return res.reduce(
|
|
26
22
|
(acc, x, i) => (acc[iters[i].key] = x.value, acc),
|
|
@@ -40,8 +36,7 @@ async function* sync(src, opts) {
|
|
|
40
36
|
tuple = {};
|
|
41
37
|
} else {
|
|
42
38
|
tuple = await $initial();
|
|
43
|
-
if (!tuple)
|
|
44
|
-
return;
|
|
39
|
+
if (!tuple) return;
|
|
45
40
|
yield { ...tuple };
|
|
46
41
|
}
|
|
47
42
|
const promises = iters.map(
|
|
@@ -51,8 +46,7 @@ async function* sync(src, opts) {
|
|
|
51
46
|
const { iter, res } = await Promise.race(promises);
|
|
52
47
|
if (res.done) {
|
|
53
48
|
promises.splice(iter.id, 1);
|
|
54
|
-
if ($remove(iter.id))
|
|
55
|
-
return;
|
|
49
|
+
if ($remove(iter.id)) return;
|
|
56
50
|
} else {
|
|
57
51
|
tuple[iter.key] = res.value;
|
|
58
52
|
yield { ...tuple };
|