mol_wire_lib 1.0.1229 → 1.0.1231

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/node.mjs CHANGED
@@ -618,7 +618,7 @@ var $;
618
618
  "use strict";
619
619
  var $;
620
620
  (function ($) {
621
- const handled = new WeakSet();
621
+ const wrappers = new WeakMap();
622
622
  class $mol_wire_fiber extends $mol_wire_pub_sub {
623
623
  task;
624
624
  host;
@@ -753,13 +753,21 @@ var $;
753
753
  result = this.task.call(this.host, ...this.args);
754
754
  break;
755
755
  }
756
- if ($mol_promise_like(result) && !handled.has(result)) {
757
- const put = (res) => {
758
- if (this.cache === result)
759
- this.put(res);
760
- return res;
761
- };
762
- result = result.then(put, put);
756
+ if ($mol_promise_like(result)) {
757
+ if (wrappers.has(result)) {
758
+ result = wrappers.get(result).then(a => a);
759
+ }
760
+ else {
761
+ const put = (res) => {
762
+ if (this.cache === result)
763
+ this.put(res);
764
+ return res;
765
+ };
766
+ wrappers.set(result, result = Object.assign(result.then(put, put), { destructor: result.destructor || (() => { }) }));
767
+ wrappers.set(result, result);
768
+ const error = new Error(`Promise in ${this}`);
769
+ Object.defineProperty(result, 'stack', { get: () => error.stack });
770
+ }
763
771
  }
764
772
  }
765
773
  catch (error) {
@@ -769,21 +777,20 @@ var $;
769
777
  else {
770
778
  result = new Error(String(error), { cause: error });
771
779
  }
772
- if ($mol_promise_like(result) && !handled.has(result)) {
773
- result = result.finally(() => {
774
- if (this.cache === result)
775
- this.absorb();
776
- });
780
+ if ($mol_promise_like(result)) {
781
+ if (wrappers.has(result)) {
782
+ result = wrappers.get(result);
783
+ }
784
+ else {
785
+ wrappers.set(result, result = Object.assign(result.finally(() => {
786
+ if (this.cache === result)
787
+ this.absorb();
788
+ }), { destructor: result.destructor || (() => { }) }));
789
+ const error = new Error(`Promise in ${this}`);
790
+ Object.defineProperty(result, 'stack', { get: () => error.stack });
791
+ }
777
792
  }
778
793
  }
779
- if ($mol_promise_like(result) && !handled.has(result)) {
780
- result = Object.assign(result, {
781
- destructor: result['destructor'] ?? (() => { })
782
- });
783
- handled.add(result);
784
- const error = new Error(`Promise in ${this}`);
785
- Object.defineProperty(result, 'stack', { get: () => error.stack });
786
- }
787
794
  if (!$mol_promise_like(result)) {
788
795
  this.track_cut();
789
796
  }
@@ -1586,6 +1593,7 @@ var $;
1586
1593
  var $;
1587
1594
  (function ($) {
1588
1595
  $.$mol_key_store = new WeakMap();
1596
+ const TypedArray = Object.getPrototypeOf(Uint8Array);
1589
1597
  function $mol_key(value) {
1590
1598
  if (typeof value === 'bigint')
1591
1599
  return value.toString() + 'n';
@@ -1615,7 +1623,7 @@ var $;
1615
1623
  return value;
1616
1624
  if (value instanceof RegExp)
1617
1625
  return value.toString();
1618
- if (value instanceof Uint8Array)
1626
+ if (value instanceof TypedArray)
1619
1627
  return [...value];
1620
1628
  let key = $.$mol_key_store.get(value);
1621
1629
  if (key)
package/node.test.js CHANGED
@@ -609,7 +609,7 @@ var $;
609
609
  "use strict";
610
610
  var $;
611
611
  (function ($) {
612
- const handled = new WeakSet();
612
+ const wrappers = new WeakMap();
613
613
  class $mol_wire_fiber extends $mol_wire_pub_sub {
614
614
  task;
615
615
  host;
@@ -744,13 +744,21 @@ var $;
744
744
  result = this.task.call(this.host, ...this.args);
745
745
  break;
746
746
  }
747
- if ($mol_promise_like(result) && !handled.has(result)) {
748
- const put = (res) => {
749
- if (this.cache === result)
750
- this.put(res);
751
- return res;
752
- };
753
- result = result.then(put, put);
747
+ if ($mol_promise_like(result)) {
748
+ if (wrappers.has(result)) {
749
+ result = wrappers.get(result).then(a => a);
750
+ }
751
+ else {
752
+ const put = (res) => {
753
+ if (this.cache === result)
754
+ this.put(res);
755
+ return res;
756
+ };
757
+ wrappers.set(result, result = Object.assign(result.then(put, put), { destructor: result.destructor || (() => { }) }));
758
+ wrappers.set(result, result);
759
+ const error = new Error(`Promise in ${this}`);
760
+ Object.defineProperty(result, 'stack', { get: () => error.stack });
761
+ }
754
762
  }
755
763
  }
756
764
  catch (error) {
@@ -760,21 +768,20 @@ var $;
760
768
  else {
761
769
  result = new Error(String(error), { cause: error });
762
770
  }
763
- if ($mol_promise_like(result) && !handled.has(result)) {
764
- result = result.finally(() => {
765
- if (this.cache === result)
766
- this.absorb();
767
- });
771
+ if ($mol_promise_like(result)) {
772
+ if (wrappers.has(result)) {
773
+ result = wrappers.get(result);
774
+ }
775
+ else {
776
+ wrappers.set(result, result = Object.assign(result.finally(() => {
777
+ if (this.cache === result)
778
+ this.absorb();
779
+ }), { destructor: result.destructor || (() => { }) }));
780
+ const error = new Error(`Promise in ${this}`);
781
+ Object.defineProperty(result, 'stack', { get: () => error.stack });
782
+ }
768
783
  }
769
784
  }
770
- if ($mol_promise_like(result) && !handled.has(result)) {
771
- result = Object.assign(result, {
772
- destructor: result['destructor'] ?? (() => { })
773
- });
774
- handled.add(result);
775
- const error = new Error(`Promise in ${this}`);
776
- Object.defineProperty(result, 'stack', { get: () => error.stack });
777
- }
778
785
  if (!$mol_promise_like(result)) {
779
786
  this.track_cut();
780
787
  }
@@ -1577,6 +1584,7 @@ var $;
1577
1584
  var $;
1578
1585
  (function ($) {
1579
1586
  $.$mol_key_store = new WeakMap();
1587
+ const TypedArray = Object.getPrototypeOf(Uint8Array);
1580
1588
  function $mol_key(value) {
1581
1589
  if (typeof value === 'bigint')
1582
1590
  return value.toString() + 'n';
@@ -1606,7 +1614,7 @@ var $;
1606
1614
  return value;
1607
1615
  if (value instanceof RegExp)
1608
1616
  return value.toString();
1609
- if (value instanceof Uint8Array)
1617
+ if (value instanceof TypedArray)
1610
1618
  return [...value];
1611
1619
  let key = $.$mol_key_store.get(value);
1612
1620
  if (key)