Skip to content

Commit

Permalink
Progress notification for Flexible Sync
Browse files Browse the repository at this point in the history
  • Loading branch information
kneth committed Dec 12, 2023
1 parent e1da25e commit ba6a5ea
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 16 deletions.
37 changes: 23 additions & 14 deletions integration-tests/tests/src/tests/sync/sync-session.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,11 @@ function createObjects(user: Realm.User, partition: string): Promise<Realm> {
resolve(realm);
}
};
//@ts-expect-error TYPEBUG: enums not exposed in realm namespace
session?.addProgressNotification("upload", "forCurrentlyOutstandingWork", callback);
session?.addProgressNotification(
Realm.ProgressDirection.Upload,
Realm.ProgressMode.ForCurrentlyOutstandingWork,
callback,
);
});
}

Expand Down Expand Up @@ -314,7 +317,7 @@ describe.skipIf(environment.missingServer, "SessionTest", () => {
await new Promise<void>((resolve, reject) => {
let syncFinished = false;
let failOnCall = false;
const progressCallback = (transferred: number, total: number) => {
const progressCallback = (transferred: number, total: number, estimate?: number) => {
unregisterFunc = () => {
realm.syncSession?.removeProgressNotification(progressCallback);
};
Expand All @@ -326,22 +329,28 @@ describe.skipIf(environment.missingServer, "SessionTest", () => {
if (syncFinished) {
failOnCall = true;
unregisterFunc();
//use second callback to wait for sync finished
//@ts-expect-error TYPEBUG: enums not exposed in realm namespace
realm.syncSession?.addProgressNotification("upload", "reportIndefinitely", (transferred, transferable) => {
if (transferred === transferable) {
resolve();
}
});
// use second callback to wait for sync finished
realm.syncSession?.addProgressNotification(
Realm.ProgressDirection.Upload,
Realm.ProgressMode.ReportIndefinitely,
(transferred, transferable, estimate) => {
if (transferred === transferable) {
resolve();
}
},
);
writeDataFunc();
}
};
//@ts-expect-error TYPEBUG: enums not exposed in realm namespace
realm.syncSession?.addProgressNotification("upload", "reportIndefinitely", progressCallback);
realm.syncSession?.addProgressNotification(
Realm.ProgressDirection.Upload,
Realm.ProgressMode.ReportIndefinitely,
progressCallback,
);
writeDataFunc();
});
await realm.close();
user.logOut();
realm.close();
await user.logOut();
});
});

Expand Down
4 changes: 3 additions & 1 deletion packages/realm/src/app-services/SyncSession.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,10 @@ export type ProgressNotificationCallback =
/**
* @param transferred - The current number of bytes already transferred
* @param transferable - The total number of transferable bytes (i.e. the number of bytes already transferred plus the number of bytes pending transfer)
* @param progressEstimate - An estimate in the range [0.0; 1.0] on the progress. The estimate is only set for flexible sync, and it is only useful
* during bootstrap. Once steady-state has been reached, the value will remain 1.0.
*/
(transferred: number, transferable: number) => void;
(transferred: number, transferable: number, progressEstimate?: number) => void;

export enum ConnectionState {
Disconnected = "disconnected",
Expand Down

0 comments on commit ba6a5ea

Please sign in to comment.