@thi.ng/csp 2.1.43 → 2.1.45
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/channel.js +19 -12
- package/mult.js +2 -1
- package/package.json +12 -12
- package/pubsub.js +2 -1
package/CHANGELOG.md
CHANGED
package/README.md
CHANGED
package/channel.js
CHANGED
|
@@ -7,7 +7,13 @@ import { delayed } from "@thi.ng/transducers/delayed";
|
|
|
7
7
|
import { range } from "@thi.ng/transducers/range";
|
|
8
8
|
import { isReduced, unreduced } from "@thi.ng/transducers/reduced";
|
|
9
9
|
import { FixedBuffer } from "./buffer.js";
|
|
10
|
-
|
|
10
|
+
var State;
|
|
11
|
+
(function (State) {
|
|
12
|
+
State[State["OPEN"] = 0] = "OPEN";
|
|
13
|
+
State[State["CLOSED"] = 1] = "CLOSED";
|
|
14
|
+
State[State["DONE"] = 2] = "DONE";
|
|
15
|
+
})(State || (State = {}));
|
|
16
|
+
class Channel {
|
|
11
17
|
static constantly(x, delay) {
|
|
12
18
|
const chan = new Channel(delay ? delayed(delay) : null);
|
|
13
19
|
chan.produce(() => x);
|
|
@@ -260,7 +266,7 @@ export class Channel {
|
|
|
260
266
|
this.txbuf = new DCons();
|
|
261
267
|
this.tx = tx ? tx(Channel.RFN) : null;
|
|
262
268
|
this.onerror = tx && (err || defaultErrorHandler);
|
|
263
|
-
this.state =
|
|
269
|
+
this.state = State.OPEN;
|
|
264
270
|
this.isBusy = false;
|
|
265
271
|
}
|
|
266
272
|
channel() {
|
|
@@ -268,7 +274,7 @@ export class Channel {
|
|
|
268
274
|
}
|
|
269
275
|
write(value) {
|
|
270
276
|
return new Promise((resolve) => {
|
|
271
|
-
if (this.state !==
|
|
277
|
+
if (this.state !== State.OPEN) {
|
|
272
278
|
resolve(false);
|
|
273
279
|
}
|
|
274
280
|
if (this.writes.length < Channel.MAX_WRITES) {
|
|
@@ -277,7 +283,7 @@ export class Channel {
|
|
|
277
283
|
? async () => {
|
|
278
284
|
try {
|
|
279
285
|
if (isReduced(this.tx[2](this.txbuf, value))) {
|
|
280
|
-
this.state =
|
|
286
|
+
this.state = State.CLOSED;
|
|
281
287
|
}
|
|
282
288
|
}
|
|
283
289
|
catch (e) {
|
|
@@ -296,7 +302,7 @@ export class Channel {
|
|
|
296
302
|
}
|
|
297
303
|
read() {
|
|
298
304
|
return new Promise((resolve) => {
|
|
299
|
-
if (this.state ===
|
|
305
|
+
if (this.state === State.DONE) {
|
|
300
306
|
resolve(undefined);
|
|
301
307
|
}
|
|
302
308
|
this.reads.push(resolve);
|
|
@@ -309,17 +315,17 @@ export class Channel {
|
|
|
309
315
|
});
|
|
310
316
|
}
|
|
311
317
|
close(flush = false) {
|
|
312
|
-
if (this.state ===
|
|
313
|
-
this.state =
|
|
318
|
+
if (this.state === State.OPEN) {
|
|
319
|
+
this.state = State.CLOSED;
|
|
314
320
|
flush && this.flush();
|
|
315
321
|
return this.process();
|
|
316
322
|
}
|
|
317
323
|
}
|
|
318
324
|
isClosed() {
|
|
319
|
-
return this.state !==
|
|
325
|
+
return this.state !== State.OPEN;
|
|
320
326
|
}
|
|
321
327
|
isReadable() {
|
|
322
|
-
return ((this.state !==
|
|
328
|
+
return ((this.state !== State.DONE && this.buf && this.buf.length > 0) ||
|
|
323
329
|
(this.writes && this.writes.length > 0) ||
|
|
324
330
|
(this.txbuf && this.txbuf.length > 0));
|
|
325
331
|
}
|
|
@@ -419,8 +425,8 @@ export class Channel {
|
|
|
419
425
|
})();
|
|
420
426
|
}
|
|
421
427
|
release() {
|
|
422
|
-
if (this.state ===
|
|
423
|
-
this.state =
|
|
428
|
+
if (this.state === State.CLOSED) {
|
|
429
|
+
this.state = State.DONE;
|
|
424
430
|
this.flush();
|
|
425
431
|
this.buf.release();
|
|
426
432
|
delete this.reads;
|
|
@@ -457,7 +463,7 @@ export class Channel {
|
|
|
457
463
|
buf.push(put);
|
|
458
464
|
put.resolve(true);
|
|
459
465
|
}
|
|
460
|
-
if (this.state ===
|
|
466
|
+
if (this.state === State.CLOSED) {
|
|
461
467
|
if (this.tx && !writes.length) {
|
|
462
468
|
try {
|
|
463
469
|
// finalize/complete transducer
|
|
@@ -498,5 +504,6 @@ Channel.RFN = [
|
|
|
498
504
|
(acc) => acc,
|
|
499
505
|
(acc, x) => acc.push(x),
|
|
500
506
|
];
|
|
507
|
+
export { Channel };
|
|
501
508
|
const defaultErrorHandler = (e, chan, val) => console.log(chan.id, "error occurred", e.message, val !== undefined ? val : "");
|
|
502
509
|
const maybeBuffer = (x) => x instanceof FixedBuffer || typeof x === "number";
|
package/mult.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { DCons } from "@thi.ng/dcons/dcons";
|
|
2
2
|
import { illegalArity } from "@thi.ng/errors/illegal-arity";
|
|
3
3
|
import { Channel } from "./channel.js";
|
|
4
|
-
|
|
4
|
+
class Mult {
|
|
5
5
|
constructor(...args) {
|
|
6
6
|
this.tapID = 0;
|
|
7
7
|
let id, src;
|
|
@@ -105,3 +105,4 @@ export class Mult {
|
|
|
105
105
|
}
|
|
106
106
|
}
|
|
107
107
|
Mult.nextID = 0;
|
|
108
|
+
export { Mult };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@thi.ng/csp",
|
|
3
|
-
"version": "2.1.
|
|
3
|
+
"version": "2.1.45",
|
|
4
4
|
"description": "ES6 promise based CSP primitives & operations",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"module": "./index.js",
|
|
@@ -38,20 +38,20 @@
|
|
|
38
38
|
"testnode": "tsc -p test && node build/test/node.js"
|
|
39
39
|
},
|
|
40
40
|
"dependencies": {
|
|
41
|
-
"@thi.ng/api": "^8.7.
|
|
42
|
-
"@thi.ng/arrays": "^2.5.
|
|
43
|
-
"@thi.ng/checks": "^3.3.
|
|
44
|
-
"@thi.ng/dcons": "^3.2.
|
|
45
|
-
"@thi.ng/errors": "^2.2.
|
|
46
|
-
"@thi.ng/transducers": "^8.
|
|
41
|
+
"@thi.ng/api": "^8.7.5",
|
|
42
|
+
"@thi.ng/arrays": "^2.5.9",
|
|
43
|
+
"@thi.ng/checks": "^3.3.11",
|
|
44
|
+
"@thi.ng/dcons": "^3.2.40",
|
|
45
|
+
"@thi.ng/errors": "^2.2.14",
|
|
46
|
+
"@thi.ng/transducers": "^8.4.1"
|
|
47
47
|
},
|
|
48
48
|
"devDependencies": {
|
|
49
49
|
"@microsoft/api-extractor": "^7.34.4",
|
|
50
|
-
"@thi.ng/testament": "^0.3.
|
|
51
|
-
"rimraf": "^4.4.
|
|
50
|
+
"@thi.ng/testament": "^0.3.14",
|
|
51
|
+
"rimraf": "^4.4.1",
|
|
52
52
|
"tools": "^0.0.1",
|
|
53
|
-
"typedoc": "^0.23.
|
|
54
|
-
"typescript": "^
|
|
53
|
+
"typedoc": "^0.23.28",
|
|
54
|
+
"typescript": "^5.0.2"
|
|
55
55
|
},
|
|
56
56
|
"keywords": [
|
|
57
57
|
"async",
|
|
@@ -102,5 +102,5 @@
|
|
|
102
102
|
"status": "deprecated",
|
|
103
103
|
"year": 2016
|
|
104
104
|
},
|
|
105
|
-
"gitHead": "
|
|
105
|
+
"gitHead": "83b15b34326d480cbca0472b20390d4d3bbb792a\n"
|
|
106
106
|
}
|
package/pubsub.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { illegalArity } from "@thi.ng/errors/illegal-arity";
|
|
2
2
|
import { Channel } from "./channel.js";
|
|
3
3
|
import { Mult } from "./mult.js";
|
|
4
|
-
|
|
4
|
+
class PubSub {
|
|
5
5
|
constructor(...args) {
|
|
6
6
|
switch (args.length) {
|
|
7
7
|
case 2:
|
|
@@ -87,3 +87,4 @@ export class PubSub {
|
|
|
87
87
|
}
|
|
88
88
|
}
|
|
89
89
|
PubSub.NEXT_ID = 0;
|
|
90
|
+
export { PubSub };
|