Skip to content

Commit

Permalink
fix: update chunking methods to send at least a single chunk
Browse files Browse the repository at this point in the history
  • Loading branch information
TejasvOnly committed Sep 23, 2024
1 parent e0b4185 commit 86b7acd
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions packages/app-inheritance/src/utils/operationHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,10 @@ export class OperationHelper<Q extends QueryKey, R extends ResultKey> {
>(data: Uint8Array, queryKey: QK, resultKey: RK) {
const chunks = OperationHelper.splitIntoChunks(data);
let remainingSize = data.length;
let i = 0;

for (let i = 0; i < chunks.length; i += 1) {
const chunk = chunks[i];
do {
const chunk = chunks[i] ?? [];
remainingSize -= chunk.length;

const chunkPayload: ChunkPayload = {
Expand All @@ -121,7 +122,8 @@ export class OperationHelper<Q extends QueryKey, R extends ResultKey> {

assertOrThrowInvalidResult(chunkAck);
assertOrThrowInvalidResult(chunkAck.chunkIndex === i);
}
i += 1;
} while (i < chunks.length);
}

public async receiveInChunks<
Expand Down Expand Up @@ -152,7 +154,7 @@ export class OperationHelper<Q extends QueryKey, R extends ResultKey> {

if (
chunkPayload.remainingSize === 0 &&
chunkPayload.chunkIndex + 1 === chunkPayload.totalChunks
chunkPayload.chunkIndex + 1 >= chunkPayload.totalChunks
) {
break;
}
Expand Down

0 comments on commit 86b7acd

Please sign in to comment.