You've already forked joplin
mirror of
https://github.com/laurent22/joplin.git
synced 2025-11-26 22:41:17 +02:00
This commit is contained in:
@@ -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_;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user