Handle the idle transition in the UI
This commit is contained in:
@@ -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.
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -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.
|
||||
|
||||
Reference in New Issue
Block a user