Handle the idle transition in the UI

This commit is contained in:
Manav Rathi
2024-08-19 14:54:18 +05:30
parent d96d4773cf
commit d7fb8cf82b
3 changed files with 7 additions and 7 deletions

View File

@@ -89,7 +89,7 @@ const worker = () =>
const createComlinkWorker = async () => {
const electron = ensureElectron();
const delegate = {
workerDidProcessFile,
workerDidProcessFileOrIdle,
};
// Obtain a message port from the Electron layer.
@@ -523,7 +523,7 @@ const setInterimScheduledStatus = () => {
setMLStatusSnapshot({ phase: "scheduled", nSyncedFiles, nTotalFiles });
};
const workerDidProcessFile = throttled(updateMLStatusSnapshot, 2000);
const workerDidProcessFileOrIdle = throttled(updateMLStatusSnapshot, 2000);
/**
* Use CLIP to perform a natural language search over image embeddings.

View File

@@ -8,11 +8,10 @@
*/
export interface MLWorkerDelegate {
/**
* Called whenever a file is processed during indexing.
*
* It is called both when the indexing was successful or it failed.
* Called whenever the worker processes a file during indexing (either
* successfully or with errors), or when in goes into the "idle" state.
*/
workerDidProcessFile: () => void;
workerDidProcessFileOrIdle: () => void;
}
/**

View File

@@ -233,6 +233,7 @@ export class MLWorker {
this.state = "idle";
this.idleDuration = Math.min(this.idleDuration * 2, idleDurationMax);
this.idleTimeout = setTimeout(scheduleTick, this.idleDuration * 1000);
this.delegate?.workerDidProcessFileOrIdle();
}
/** Return the next batch of items to backfill (if any). */
@@ -320,7 +321,7 @@ const indexNextBatch = async (
await Promise.race(tasks);
// Let the main thread now we're doing something.
delegate?.workerDidProcessFile();
delegate?.workerDidProcessFileOrIdle();
// Let us drain the microtask queue. This also gives a chance for other
// interactive tasks like `clipMatches` to run.