Skip to content

Commit

Permalink
Merge branch 'fix/inheritance/chunking-for-empty-message' into feat/i…
Browse files Browse the repository at this point in the history
…nheritances/session/refactor
  • Loading branch information
irshadjsr21 committed Sep 23, 2024
2 parents 0b857b9 + b4b3660 commit 70c4333
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions packages/app-inheritance/src/utils/operationHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,15 +94,16 @@ 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 = {
chunk,
chunkIndex: i,
totalChunks: chunks.length,
totalChunks: Math.max(chunks.length, 1),
remainingSize,
};

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 70c4333

Please sign in to comment.