mol_wire_lib 1.0.1808 → 1.0.1809
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/giper/baza/diagram/dict.png +0 -0
- package/giper/baza/diagram/gift.png +0 -0
- package/giper/baza/diagram/jepsen.png +0 -0
- package/giper/baza/diagram/json.png +0 -0
- package/giper/baza/diagram/list.png +0 -0
- package/giper/baza/diagram/network.png +0 -0
- package/giper/baza/diagram/pack.png +0 -0
- package/giper/baza/diagram/pass.png +0 -0
- package/giper/baza/diagram/reg.png +0 -0
- package/giper/baza/diagram/rich.png +0 -0
- package/giper/baza/diagram/sand.png +0 -0
- package/giper/baza/diagram/sync.png +0 -0
- package/giper/baza/diagram/text.png +0 -0
- package/giper/baza/diagram/tree.png +0 -0
- package/giper/baza/logo/bg.webp +0 -0
- package/giper/baza/logo/logo-512.png +0 -0
- package/giper/baza/logo/logo.svg +3 -0
- package/node.d.ts +8 -3
- package/node.d.ts.map +1 -1
- package/node.deps.json +1 -1
- package/node.js +97 -69
- package/node.js.map +1 -1
- package/node.mjs +97 -69
- package/node.test.js +14459 -367
- package/node.test.js.map +1 -1
- package/package.json +4 -4
- package/web.d.ts +8 -3
- package/web.d.ts.map +1 -1
- package/web.deps.json +1 -1
- package/web.js +97 -69
- package/web.js.map +1 -1
- package/web.mjs +97 -69
- package/web.test.js +32318 -318
- package/web.test.js.map +1 -1
package/web.mjs
CHANGED
|
@@ -65,10 +65,12 @@ var $;
|
|
|
65
65
|
$mol_wire_cursor[$mol_wire_cursor["stale"] = -1] = "stale";
|
|
66
66
|
/** Some of (transitive) pub update required. */
|
|
67
67
|
$mol_wire_cursor[$mol_wire_cursor["doubt"] = -2] = "doubt";
|
|
68
|
+
/** Doubt check in progress, so any incoming quant is noticeable. */
|
|
69
|
+
$mol_wire_cursor[$mol_wire_cursor["check"] = -3] = "check";
|
|
68
70
|
/** Actual state but may be dropped. */
|
|
69
|
-
$mol_wire_cursor[$mol_wire_cursor["fresh"] = -
|
|
71
|
+
$mol_wire_cursor[$mol_wire_cursor["fresh"] = -4] = "fresh";
|
|
70
72
|
/** State will never be changed. */
|
|
71
|
-
$mol_wire_cursor[$mol_wire_cursor["final"] = -
|
|
73
|
+
$mol_wire_cursor[$mol_wire_cursor["final"] = -5] = "final";
|
|
72
74
|
})($mol_wire_cursor = $.$mol_wire_cursor || ($.$mol_wire_cursor = {}));
|
|
73
75
|
})($ || ($ = {}));
|
|
74
76
|
|
|
@@ -147,6 +149,12 @@ var $;
|
|
|
147
149
|
* Enforce actualization. Should not throw errors.
|
|
148
150
|
*/
|
|
149
151
|
fresh() { }
|
|
152
|
+
/**
|
|
153
|
+
* Lives inside single calculation of subscriber or not.
|
|
154
|
+
*/
|
|
155
|
+
get temp() {
|
|
156
|
+
return false;
|
|
157
|
+
}
|
|
150
158
|
/**
|
|
151
159
|
* Allow to put data to caches in the subtree.
|
|
152
160
|
*/
|
|
@@ -443,9 +451,6 @@ var $;
|
|
|
443
451
|
class $mol_wire_pub_sub extends $mol_wire_pub {
|
|
444
452
|
pub_from = 0; // 4B
|
|
445
453
|
cursor = $mol_wire_cursor.stale; // 4B
|
|
446
|
-
get temp() {
|
|
447
|
-
return false;
|
|
448
|
-
}
|
|
449
454
|
get pub_list() {
|
|
450
455
|
const res = [];
|
|
451
456
|
const max = this.cursor >= 0 ? this.cursor : this.sub_from;
|
|
@@ -465,6 +470,9 @@ var $;
|
|
|
465
470
|
if (this.cursor >= this.pub_from) {
|
|
466
471
|
$mol_fail(new Error('Circular subscription'));
|
|
467
472
|
}
|
|
473
|
+
if (this.cursor === $mol_wire_cursor.check) {
|
|
474
|
+
$mol_fail(new Error('Circular checking'));
|
|
475
|
+
}
|
|
468
476
|
super.promote();
|
|
469
477
|
}
|
|
470
478
|
track_next(pub) {
|
|
@@ -506,7 +514,8 @@ var $;
|
|
|
506
514
|
}
|
|
507
515
|
for (let cursor = this.pub_from; cursor < this.cursor; cursor += 2) {
|
|
508
516
|
const pub = this.data[cursor];
|
|
509
|
-
|
|
517
|
+
// Slot may be cleared by pub_off when a temp was destroyed mid-calc.
|
|
518
|
+
pub?.fresh();
|
|
510
519
|
}
|
|
511
520
|
this.cursor = $mol_wire_cursor.fresh;
|
|
512
521
|
}
|
|
@@ -515,6 +524,10 @@ var $;
|
|
|
515
524
|
this.data[sub_pos + 1] = undefined;
|
|
516
525
|
}
|
|
517
526
|
destructor() {
|
|
527
|
+
// Mid-calc destroy (absorb restarts a temp): stop promoting into this
|
|
528
|
+
// fiber so track_next does not throw 'Promo to non begun sub'.
|
|
529
|
+
if ($mol_wire_auto() === this)
|
|
530
|
+
$mol_wire_auto(null);
|
|
518
531
|
for (let cursor = this.data.length - 2; cursor >= this.sub_from; cursor -= 2) {
|
|
519
532
|
const sub = this.data[cursor];
|
|
520
533
|
const pos = this.data[cursor + 1];
|
|
@@ -560,20 +573,21 @@ var $;
|
|
|
560
573
|
return;
|
|
561
574
|
this.cursor = quant;
|
|
562
575
|
this.emit($mol_wire_cursor.doubt);
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
//
|
|
568
|
-
//
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
576
|
+
if (quant !== $mol_wire_cursor.stale)
|
|
577
|
+
return;
|
|
578
|
+
if (!this.incompleted)
|
|
579
|
+
return;
|
|
580
|
+
// Notice from own task resumes the same calculation, but from a regular
|
|
581
|
+
// pub it makes awaited tasks based on outdated data, so restart them.
|
|
582
|
+
const pub = this.data[pos];
|
|
583
|
+
if (pub?.temp)
|
|
584
|
+
return;
|
|
585
|
+
for (let cursor = this.pub_from; cursor < this.sub_from; cursor += 2) {
|
|
586
|
+
const pub = this.data[cursor];
|
|
587
|
+
if (pub?.temp) {
|
|
588
|
+
pub.destructor();
|
|
589
|
+
}
|
|
590
|
+
}
|
|
577
591
|
}
|
|
578
592
|
[$mol_dev_format_head]() {
|
|
579
593
|
return $mol_dev_format_native(this);
|
|
@@ -934,7 +948,8 @@ var $;
|
|
|
934
948
|
[$mol_dev_format_head]() {
|
|
935
949
|
const cursor = {
|
|
936
950
|
[$mol_wire_cursor.stale]: '🔴',
|
|
937
|
-
[$mol_wire_cursor.doubt]: '
|
|
951
|
+
[$mol_wire_cursor.doubt]: '🟠',
|
|
952
|
+
[$mol_wire_cursor.check]: '🟡',
|
|
938
953
|
[$mol_wire_cursor.fresh]: '🟢',
|
|
939
954
|
[$mol_wire_cursor.final]: '🔵',
|
|
940
955
|
}[this.cursor] ?? this.cursor.toString();
|
|
@@ -958,10 +973,11 @@ var $;
|
|
|
958
973
|
if (this.cursor === $mol_wire_cursor.final)
|
|
959
974
|
return;
|
|
960
975
|
check: if (this.cursor === $mol_wire_cursor.doubt) {
|
|
976
|
+
this.cursor = $mol_wire_cursor.check;
|
|
961
977
|
for (let i = this.pub_from; i < this.sub_from; i += 2) {
|
|
962
978
|
;
|
|
963
979
|
this.data[i]?.fresh();
|
|
964
|
-
if (this.cursor !== $mol_wire_cursor.
|
|
980
|
+
if (this.cursor !== $mol_wire_cursor.check)
|
|
965
981
|
break check;
|
|
966
982
|
}
|
|
967
983
|
this.cursor = $mol_wire_cursor.fresh;
|
|
@@ -970,62 +986,74 @@ var $;
|
|
|
970
986
|
const bu = this.track_on();
|
|
971
987
|
let result;
|
|
972
988
|
try {
|
|
973
|
-
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
if ($mol_promise_like(result)) {
|
|
985
|
-
if (wrappers.has(result)) {
|
|
986
|
-
result = wrappers.get(result).then(a => a);
|
|
989
|
+
try {
|
|
990
|
+
switch (this.pub_from) {
|
|
991
|
+
case 0:
|
|
992
|
+
result = this.task.call(this.host);
|
|
993
|
+
break;
|
|
994
|
+
case 1:
|
|
995
|
+
result = this.task.call(this.host, this.data[0]);
|
|
996
|
+
break;
|
|
997
|
+
default:
|
|
998
|
+
result = this.task.call(this.host, ...this.args);
|
|
999
|
+
break;
|
|
987
1000
|
}
|
|
988
|
-
|
|
989
|
-
|
|
990
|
-
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
|
|
996
|
-
|
|
997
|
-
|
|
1001
|
+
if ($mol_promise_like(result)) {
|
|
1002
|
+
if (wrappers.has(result)) {
|
|
1003
|
+
result = wrappers.get(result).then(a => a);
|
|
1004
|
+
}
|
|
1005
|
+
else {
|
|
1006
|
+
const put = (res) => {
|
|
1007
|
+
if (this.cache === result)
|
|
1008
|
+
this.put(res);
|
|
1009
|
+
return res;
|
|
1010
|
+
};
|
|
1011
|
+
wrappers.set(result, result = Object.assign(result.then(put, put), { destructor: result.destructor || (() => { }) }));
|
|
1012
|
+
wrappers.set(result, result);
|
|
1013
|
+
const error = new Error(`Promise in ${this}`);
|
|
1014
|
+
Object.defineProperty(result, 'stack', { get: () => error.stack });
|
|
1015
|
+
}
|
|
998
1016
|
}
|
|
999
1017
|
}
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
result = error;
|
|
1004
|
-
}
|
|
1005
|
-
else {
|
|
1006
|
-
result = new Error(String(error), { cause: error });
|
|
1007
|
-
}
|
|
1008
|
-
if ($mol_promise_like(result)) {
|
|
1009
|
-
if (wrappers.has(result)) {
|
|
1010
|
-
result = wrappers.get(result);
|
|
1018
|
+
catch (error) {
|
|
1019
|
+
if (error instanceof Error || $mol_promise_like(error)) {
|
|
1020
|
+
result = error;
|
|
1011
1021
|
}
|
|
1012
1022
|
else {
|
|
1013
|
-
|
|
1014
|
-
if (this.cache === result)
|
|
1015
|
-
this.absorb();
|
|
1016
|
-
return v;
|
|
1017
|
-
};
|
|
1018
|
-
wrappers.set(result, result = Object.assign(result.then(put, put), { destructor: result.destructor || (() => { }) }));
|
|
1019
|
-
const error = new Error(`Promise in ${this}`);
|
|
1020
|
-
Object.defineProperty(result, 'stack', { get: () => error.stack });
|
|
1023
|
+
result = new Error(String(error), { cause: error });
|
|
1021
1024
|
}
|
|
1025
|
+
if ($mol_promise_like(result)) {
|
|
1026
|
+
if (wrappers.has(result)) {
|
|
1027
|
+
result = wrappers.get(result);
|
|
1028
|
+
}
|
|
1029
|
+
else {
|
|
1030
|
+
const put = (v) => {
|
|
1031
|
+
if (this.cache === result)
|
|
1032
|
+
this.absorb();
|
|
1033
|
+
return v;
|
|
1034
|
+
};
|
|
1035
|
+
wrappers.set(result, result = Object.assign(result.then(put, put), { destructor: result.destructor || (() => { }) }));
|
|
1036
|
+
const error = new Error(`Promise in ${this}`);
|
|
1037
|
+
Object.defineProperty(result, 'stack', { get: () => error.stack });
|
|
1038
|
+
}
|
|
1039
|
+
}
|
|
1040
|
+
}
|
|
1041
|
+
// Temp destroyed mid-calc (absorb restart): cut/off would throw.
|
|
1042
|
+
if (this.cursor < this.pub_from)
|
|
1043
|
+
return this;
|
|
1044
|
+
if (!$mol_promise_like(result)) {
|
|
1045
|
+
this.track_cut();
|
|
1022
1046
|
}
|
|
1047
|
+
this.track_off(bu);
|
|
1048
|
+
this.put(result);
|
|
1023
1049
|
}
|
|
1024
|
-
|
|
1025
|
-
|
|
1050
|
+
finally {
|
|
1051
|
+
// If cut threw or destructor nulled auto — put outer back
|
|
1052
|
+
// (else once()/onclose → Promo to non begun sub).
|
|
1053
|
+
if ($mol_wire_auto() === this || !$mol_wire_auto()) {
|
|
1054
|
+
$mol_wire_auto(bu);
|
|
1055
|
+
}
|
|
1026
1056
|
}
|
|
1027
|
-
this.track_off(bu);
|
|
1028
|
-
this.put(result);
|
|
1029
1057
|
return this;
|
|
1030
1058
|
}
|
|
1031
1059
|
refresh() {
|