@actuallab/rpc 12.3.81 → 12.3.83

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
@@ -1062,6 +1062,7 @@ declare class RpcStream<T> implements AsyncIterable<T>, IRpcObject {
1062
1062
  private _started;
1063
1063
  private _iterating;
1064
1064
  private _ackSentUpTo;
1065
+ private _nextConsumedIndex;
1065
1066
  /** Create a local (origin-side) stream wrapping an async iterable or source factory with optional configuration. */
1066
1067
  constructor(source: RpcStreamSource<T>, options?: RpcStreamOptions<T>);
1067
1068
  /** Create a remote (target-side) stream from a parsed stream reference and peer. */
package/dist/index.d.ts CHANGED
@@ -1062,6 +1062,7 @@ declare class RpcStream<T> implements AsyncIterable<T>, IRpcObject {
1062
1062
  private _started;
1063
1063
  private _iterating;
1064
1064
  private _ackSentUpTo;
1065
+ private _nextConsumedIndex;
1065
1066
  /** Create a local (origin-side) stream wrapping an async iterable or source factory with optional configuration. */
1066
1067
  constructor(source: RpcStreamSource<T>, options?: RpcStreamOptions<T>);
1067
1068
  /** Create a remote (target-side) stream from a parsed stream reference and peer. */
package/dist/index.js CHANGED
@@ -1377,6 +1377,7 @@ var RpcStream = class _RpcStream {
1377
1377
  _started = false;
1378
1378
  _iterating = false;
1379
1379
  _ackSentUpTo = 0;
1380
+ _nextConsumedIndex = 0;
1380
1381
  constructor(sourceOrRef, optionsOrPeer) {
1381
1382
  if (_isStreamSource(sourceOrRef)) {
1382
1383
  const options = optionsOrPeer ?? {};
@@ -1468,12 +1469,11 @@ var RpcStream = class _RpcStream {
1468
1469
  return;
1469
1470
  }
1470
1471
  if (index < this._nextExpectedIndex) {
1471
- this._maybeSendAck(index + 1);
1472
+ this._maybeSendAck(Math.min(index + 1, this._nextConsumedIndex));
1472
1473
  return;
1473
1474
  }
1474
1475
  this._buffer.push(item);
1475
1476
  this._nextExpectedIndex = index + 1;
1476
- this._maybeSendAck(this._nextExpectedIndex);
1477
1477
  this._notifyConsumer();
1478
1478
  }
1479
1479
  /** Called by system call handler when a batch arrives ($sys.B). */
@@ -1493,12 +1493,11 @@ var RpcStream = class _RpcStream {
1493
1493
  return;
1494
1494
  }
1495
1495
  if (index < this._nextExpectedIndex) {
1496
- this._maybeSendAck(index + items.length);
1496
+ this._maybeSendAck(Math.min(index + items.length, this._nextConsumedIndex));
1497
1497
  return;
1498
1498
  }
1499
1499
  for (const item of items) this._buffer.push(item);
1500
1500
  this._nextExpectedIndex = index + items.length;
1501
- this._maybeSendAck(this._nextExpectedIndex);
1502
1501
  this._notifyConsumer();
1503
1502
  }
1504
1503
  /** Called by system call handler when the stream ends ($sys.End). */
@@ -1542,9 +1541,11 @@ var RpcStream = class _RpcStream {
1542
1541
  this._started = true;
1543
1542
  this._sendAck(0, true);
1544
1543
  }
1544
+ this._maybeSendAck(this._nextConsumedIndex);
1545
1545
  for (; ; ) {
1546
1546
  if (!this._buffer.isEmpty()) {
1547
1547
  const value = this._buffer.shift();
1548
+ this._nextConsumedIndex++;
1548
1549
  return { value, done: false };
1549
1550
  }
1550
1551
  if (this._completed) {