@actuallab/rpc 14.3.34 → 14.4.3

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/dist/index.d.cts CHANGED
@@ -409,7 +409,8 @@ declare class RpcCallTimeouts {
409
409
  static readonly None: RpcCallTimeouts;
410
410
  /** Command default: 1.5 s connect / 10 s run (.NET `RpcCallTimeouts.Default.Command`). */
411
411
  static readonly Command: RpcCallTimeouts;
412
- /** Max time a call may wait for the connection before it is sent. */
412
+ /** Max time a call may wait for a connection - before it is sent, and again for the
413
+ * duration of any outage it is still pending through. */
413
414
  readonly connectTimeoutMs: number;
414
415
  /** Max time a sent call may stay unanswered before it is failed. */
415
416
  readonly runTimeoutMs: number;
@@ -1003,6 +1004,8 @@ declare abstract class RpcPeer {
1003
1004
  /** Wall-clock time of the last inbound `$sys.KeepAlive`, or 0 if none yet
1004
1005
  * for the current connection. Useful for diagnostics. */
1005
1006
  private _lastKeepAliveAt;
1007
+ /** When the current outage began; 0 until the peer has been connected at least once. */
1008
+ private _disconnectedAt;
1006
1009
  /** Outbound keep-alive send period. Initialized from `hub.limits` at
1007
1010
  * construction; set directly to override on a single peer. */
1008
1011
  keepAlivePeriodMs: number;
@@ -1012,9 +1015,10 @@ declare abstract class RpcPeer {
1012
1015
  protected constructor(hub: RpcHub, ref: string);
1013
1016
  /** Fail outbound calls whose per-call {@link RpcCallTimeouts} elapsed —
1014
1017
  * the connect timeout while a call still awaits the wire, the run timeout
1015
- * once it has been sent. Mirrors .NET `RpcOutboundCallTracker.Maintain`
1016
- * (RpcCallTrackers.cs:108-207). Calls without timeouts (queries) never
1017
- * time out here. */
1018
+ * once it has been sent, and the connect timeout again for any pending call while the
1019
+ * peer is away. Mirrors .NET `RpcOutboundCallTracker.HandleDisconnect` (ConnectTimeout,
1020
+ * per outage) plus `Maintain` (RunTimeout, per connection). Calls without timeouts
1021
+ * (queries) never time out here. */
1018
1022
  private _maintainOutboundCalls;
1019
1023
  get connection(): RpcConnection | undefined;
1020
1024
  get connectionState(): RpcConnectionState;
package/dist/index.d.ts CHANGED
@@ -409,7 +409,8 @@ declare class RpcCallTimeouts {
409
409
  static readonly None: RpcCallTimeouts;
410
410
  /** Command default: 1.5 s connect / 10 s run (.NET `RpcCallTimeouts.Default.Command`). */
411
411
  static readonly Command: RpcCallTimeouts;
412
- /** Max time a call may wait for the connection before it is sent. */
412
+ /** Max time a call may wait for a connection - before it is sent, and again for the
413
+ * duration of any outage it is still pending through. */
413
414
  readonly connectTimeoutMs: number;
414
415
  /** Max time a sent call may stay unanswered before it is failed. */
415
416
  readonly runTimeoutMs: number;
@@ -1003,6 +1004,8 @@ declare abstract class RpcPeer {
1003
1004
  /** Wall-clock time of the last inbound `$sys.KeepAlive`, or 0 if none yet
1004
1005
  * for the current connection. Useful for diagnostics. */
1005
1006
  private _lastKeepAliveAt;
1007
+ /** When the current outage began; 0 until the peer has been connected at least once. */
1008
+ private _disconnectedAt;
1006
1009
  /** Outbound keep-alive send period. Initialized from `hub.limits` at
1007
1010
  * construction; set directly to override on a single peer. */
1008
1011
  keepAlivePeriodMs: number;
@@ -1012,9 +1015,10 @@ declare abstract class RpcPeer {
1012
1015
  protected constructor(hub: RpcHub, ref: string);
1013
1016
  /** Fail outbound calls whose per-call {@link RpcCallTimeouts} elapsed —
1014
1017
  * the connect timeout while a call still awaits the wire, the run timeout
1015
- * once it has been sent. Mirrors .NET `RpcOutboundCallTracker.Maintain`
1016
- * (RpcCallTrackers.cs:108-207). Calls without timeouts (queries) never
1017
- * time out here. */
1018
+ * once it has been sent, and the connect timeout again for any pending call while the
1019
+ * peer is away. Mirrors .NET `RpcOutboundCallTracker.HandleDisconnect` (ConnectTimeout,
1020
+ * per outage) plus `Maintain` (RunTimeout, per connection). Calls without timeouts
1021
+ * (queries) never time out here. */
1018
1022
  private _maintainOutboundCalls;
1019
1023
  get connection(): RpcConnection | undefined;
1020
1024
  get connectionState(): RpcConnectionState;
package/dist/index.js CHANGED
@@ -879,7 +879,8 @@ var RpcCallTimeouts = class _RpcCallTimeouts {
879
879
  static None = new _RpcCallTimeouts(Infinity, Infinity);
880
880
  /** Command default: 1.5 s connect / 10 s run (.NET `RpcCallTimeouts.Default.Command`). */
881
881
  static Command = new _RpcCallTimeouts(1500, 1e4);
882
- /** Max time a call may wait for the connection before it is sent. */
882
+ /** Max time a call may wait for a connection - before it is sent, and again for the
883
+ * duration of any outage it is still pending through. */
883
884
  connectTimeoutMs;
884
885
  /** Max time a sent call may stay unanswered before it is failed. */
885
886
  runTimeoutMs;
@@ -2673,6 +2674,8 @@ var RpcPeer = class {
2673
2674
  /** Wall-clock time of the last inbound `$sys.KeepAlive`, or 0 if none yet
2674
2675
  * for the current connection. Useful for diagnostics. */
2675
2676
  _lastKeepAliveAt = 0;
2677
+ /** When the current outage began; 0 until the peer has been connected at least once. */
2678
+ _disconnectedAt = 0;
2676
2679
  /** Outbound keep-alive send period. Initialized from `hub.limits` at
2677
2680
  * construction; set directly to override on a single peer. */
2678
2681
  keepAlivePeriodMs;
@@ -2693,9 +2696,10 @@ var RpcPeer = class {
2693
2696
  }
2694
2697
  /** Fail outbound calls whose per-call {@link RpcCallTimeouts} elapsed —
2695
2698
  * the connect timeout while a call still awaits the wire, the run timeout
2696
- * once it has been sent. Mirrors .NET `RpcOutboundCallTracker.Maintain`
2697
- * (RpcCallTrackers.cs:108-207). Calls without timeouts (queries) never
2698
- * time out here. */
2699
+ * once it has been sent, and the connect timeout again for any pending call while the
2700
+ * peer is away. Mirrors .NET `RpcOutboundCallTracker.HandleDisconnect` (ConnectTimeout,
2701
+ * per outage) plus `Maintain` (RunTimeout, per connection). Calls without timeouts
2702
+ * (queries) never time out here. */
2699
2703
  _maintainOutboundCalls() {
2700
2704
  const now = Date.now();
2701
2705
  const canRunTimeout = this._isConnected && (this._lastKeepAliveAt === 0 || now - this._lastKeepAliveAt <= this.keepAliveTimeoutMs);
@@ -2704,7 +2708,11 @@ var RpcPeer = class {
2704
2708
  if (timeouts === void 0 || call.result.isCompleted)
2705
2709
  continue;
2706
2710
  let timedOut;
2707
- if (call.sentAt === 0) {
2711
+ if (!this._isConnected) {
2712
+ const since = Math.max(this._disconnectedAt, call.startedAt);
2713
+ if (now - since >= timeouts.connectTimeoutMs)
2714
+ timedOut = `connect timeout (${timeouts.connectTimeoutMs}ms)`;
2715
+ } else if (call.sentAt === 0) {
2708
2716
  if (now - call.startedAt >= timeouts.connectTimeoutMs)
2709
2717
  timedOut = `connect timeout (${timeouts.connectTimeoutMs}ms)`;
2710
2718
  } else if (canRunTimeout && now - call.sentAt >= timeouts.runTimeoutMs)
@@ -2747,10 +2755,13 @@ var RpcPeer = class {
2747
2755
  this._connectionState = value;
2748
2756
  if (value === 3 /* Connected */) {
2749
2757
  this._isConnected = true;
2758
+ this._disconnectedAt = 0;
2750
2759
  this._armKeepAliveWatchdog();
2751
2760
  } else if (value === 0 /* Disconnected */) {
2752
- if (previousState === 3 /* Connected */)
2761
+ if (previousState === 3 /* Connected */) {
2753
2762
  this._isConnected = false;
2763
+ this._disconnectedAt = Date.now();
2764
+ }
2754
2765
  this._disarmKeepAliveWatchdog();
2755
2766
  }
2756
2767
  this.connectionStateChanged.trigger(value);
@@ -2775,6 +2786,8 @@ var RpcPeer = class {
2775
2786
  conn.closed.add((ev) => {
2776
2787
  if (this._connection !== conn) return;
2777
2788
  this._connection = void 0;
2789
+ if (this._isConnected)
2790
+ this._disconnectedAt = Date.now();
2778
2791
  this._isConnected = false;
2779
2792
  if (ev.reason)
2780
2793
  infoLog?.log(`'${this.ref}': Disconnected: ${ev.reason} (code=${ev.code})`);