1
0
mirror of https://github.com/laurent22/joplin.git synced 2025-11-26 22:41:17 +02:00

Desktop: Fixes #10284: Sort the note list soon after changing a note's title (#10512)

This commit is contained in:
Henry Heino
2024-05-30 00:40:32 -07:00
committed by GitHub
parent 55c222c577
commit 99b840da34
4 changed files with 39 additions and 22 deletions

View File

@@ -28,9 +28,19 @@ export default class AsyncActionQueue {
private scheduleProcessingIID_: any = null;
private processing_ = false;
private processingFinishedPromise_: Promise<void>;
private onProcessingFinished_: ()=> void;
public constructor(interval = 100, intervalType: IntervalType = IntervalType.Debounce) {
this.interval_ = interval;
this.intervalType_ = intervalType;
this.resetFinishProcessingPromise_();
}
private resetFinishProcessingPromise_() {
this.processingFinishedPromise_ = new Promise<void>(resolve => {
this.onProcessingFinished_ = resolve;
});
}
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- Old code before rule was applied
@@ -77,6 +87,11 @@ export default class AsyncActionQueue {
}
this.processing_ = false;
if (this.queue_.length === 0) {
this.onProcessingFinished_();
this.resetFinishProcessingPromise_();
}
}
public async reset() {
@@ -86,30 +101,17 @@ export default class AsyncActionQueue {
}
this.queue_ = [];
return this.waitForAllDone();
return this.processAllNow();
}
// Currently waitForAllDone() already finishes all the actions
// as quickly as possible so we can make it an alias.
public async processAllNow() {
this.scheduleProcessing(1);
return this.waitForAllDone();
}
public async waitForAllDone() {
if (!this.queue_.length) return Promise.resolve();
this.scheduleProcessing(1);
return new Promise((resolve) => {
const iid = shim.setInterval(() => {
if (this.processing_) return;
if (!this.queue_.length) {
shim.clearInterval(iid);
resolve(null);
}
}, 100);
});
return this.processingFinishedPromise_;
}
}