@thi.ng/transducers-async 0.2.3 → 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 CHANGED
@@ -1,6 +1,6 @@
1
1
  # Change Log
2
2
 
3
- - **Last updated**: 2024-04-25T19:44:55Z
3
+ - **Last updated**: 2024-05-08T18:24:31Z
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.
package/README.md CHANGED
@@ -116,7 +116,7 @@ For Node.js REPL:
116
116
  const txa = await import("@thi.ng/transducers-async");
117
117
  ```
118
118
 
119
- Package sizes (brotli'd, pre-treeshake): ESM: 3.10 KB
119
+ Package sizes (brotli'd, pre-treeshake): ESM: 3.11 KB
120
120
 
121
121
  ## Dependencies
122
122
 
@@ -129,13 +129,14 @@ Package sizes (brotli'd, pre-treeshake): ESM: 3.10 KB
129
129
 
130
130
  ## Usage examples
131
131
 
132
- One project in this repo's
132
+ Several projects in this repo's
133
133
  [/examples](https://github.com/thi-ng/umbrella/tree/develop/examples)
134
- directory is using this package:
134
+ directory are using this package:
135
135
 
136
- | Description | Live demo | Source |
137
- |:----------------------------------------------------------|:-------------------------------------------------|:------------------------------------------------------------------------------|
138
- | Basic & barebones usage of async iterables in thi.ng/rdom | [Demo](https://demo.thi.ng/umbrella/rdom-async/) | [Source](https://github.com/thi-ng/umbrella/tree/develop/examples/rdom-async) |
136
+ | Screenshot | Description | Live demo | Source |
137
+ |:---------------------------------------------------------------------------------------------------------------|:-----------------------------------------------------------------------------|:-------------------------------------------------|:------------------------------------------------------------------------------|
138
+ | <img src="https://raw.githubusercontent.com/thi-ng/umbrella/develop/assets/examples/csp-bus.png" width="240"/> | CSP channel-based event handling, async transducers & reactive UI components | [Demo](https://demo.thi.ng/umbrella/csp-bus/) | [Source](https://github.com/thi-ng/umbrella/tree/develop/examples/csp-bus) |
139
+ | | Basic & barebones usage of async iterables in thi.ng/rdom | [Demo](https://demo.thi.ng/umbrella/rdom-async/) | [Source](https://github.com/thi-ng/umbrella/tree/develop/examples/rdom-async) |
139
140
 
140
141
  ## API
141
142
 
package/as-async.js CHANGED
@@ -2,8 +2,7 @@ import { wait } from "./delayed.js";
2
2
  async function* asAsyncIterable(src, delay = 0) {
3
3
  for (let x of src) {
4
4
  yield x;
5
- if (delay > 0)
6
- await wait(delay);
5
+ if (delay > 0) await wait(delay);
7
6
  }
8
7
  }
9
8
  export {
package/cat.js CHANGED
@@ -6,8 +6,7 @@ const cat = () => (rfn) => {
6
6
  if (x != null) {
7
7
  for await (let y of x) {
8
8
  acc = await r(acc, y);
9
- if (isReduced(acc))
10
- return acc.deref();
9
+ if (isReduced(acc)) return acc.deref();
11
10
  }
12
11
  }
13
12
  return acc;
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
- return true;
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
- s.resolve(val);
23
- if (val === void 0)
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",
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.1",
40
- "@thi.ng/buffers": "^0.1.2",
41
- "@thi.ng/checks": "^3.6.3",
42
- "@thi.ng/compose": "^3.0.3",
43
- "@thi.ng/errors": "^2.5.6",
44
- "@thi.ng/transducers": "^9.0.4"
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.0",
48
- "esbuild": "^0.20.2",
49
- "typedoc": "^0.25.12",
50
- "typescript": "^5.4.3"
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": "aed3421c21044c005fbcb7cc37965ccf85a870d2\n"
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
- continue;
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
@@ -2,8 +2,7 @@ import { reducer } from "./reduce.js";
2
2
  function push(xs) {
3
3
  return xs ? (async () => {
4
4
  let res = [];
5
- for await (let x of xs)
6
- res.push(x);
5
+ for await (let x of xs) res.push(x);
7
6
  return res;
8
7
  })() : reducer(
9
8
  () => [],
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
- t0 = t;
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
- buf[0] = res.value;
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
- state = 1;
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
- return true;
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
- return;
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 };
package/zip.js CHANGED
@@ -6,8 +6,7 @@ async function* zip(...src) {
6
6
  const tuple = [];
7
7
  for (let i of iters) {
8
8
  let v = await i.next();
9
- if (v.done)
10
- return;
9
+ if (v.done) return;
11
10
  tuple.push(v.value);
12
11
  }
13
12
  yield tuple;