mirror of
https://github.com/ether/etherpad-lite.git
synced 2025-06-15 10:44:41 -04:00
collab_client: Implement callWhenNotCommitting()
with a Gate
This commit is contained in:
parent
e5375fe425
commit
1adf24db79
1 changed files with 7 additions and 16 deletions
|
@ -102,7 +102,8 @@ class CollabClient {
|
||||||
|
|
||||||
this._serverMessageTaskQueue = new TaskQueue();
|
this._serverMessageTaskQueue = new TaskQueue();
|
||||||
|
|
||||||
this._idleFuncs = [];
|
this._idleGate = new Gate();
|
||||||
|
this._idleGate.open();
|
||||||
|
|
||||||
this.addHistoricalAuthors(serverVars.historicalAuthorData);
|
this.addHistoricalAuthors(serverVars.historicalAuthorData);
|
||||||
this._tellAceActiveAuthorInfo(this._initialUserInfo);
|
this._tellAceActiveAuthorInfo(this._initialUserInfo);
|
||||||
|
@ -157,6 +158,7 @@ class CollabClient {
|
||||||
if (userChangesData.changeset) {
|
if (userChangesData.changeset) {
|
||||||
this._lastCommitTime = now;
|
this._lastCommitTime = now;
|
||||||
this._committing = true;
|
this._committing = true;
|
||||||
|
this._idleGate = new Gate();
|
||||||
this._stateMessage = {
|
this._stateMessage = {
|
||||||
type: 'USER_CHANGES',
|
type: 'USER_CHANGES',
|
||||||
baseRev: this._rev,
|
baseRev: this._rev,
|
||||||
|
@ -434,28 +436,17 @@ class CollabClient {
|
||||||
|
|
||||||
setStateIdle() {
|
setStateIdle() {
|
||||||
this._committing = false;
|
this._committing = false;
|
||||||
|
this._idleGate.open();
|
||||||
this._callbacks.onInternalAction('newlyIdle');
|
this._callbacks.onInternalAction('newlyIdle');
|
||||||
this._schedulePerhapsCallIdleFuncs();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
setIsPendingRevision(value) {
|
setIsPendingRevision(value) {
|
||||||
this._isPendingRevision = value;
|
this._isPendingRevision = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
callWhenNotCommitting(func) {
|
async callWhenNotCommitting(func) {
|
||||||
this._idleFuncs.push(func);
|
await this._idleGate;
|
||||||
this._schedulePerhapsCallIdleFuncs();
|
return await func();
|
||||||
}
|
|
||||||
|
|
||||||
_schedulePerhapsCallIdleFuncs() {
|
|
||||||
setTimeout(() => {
|
|
||||||
if (!this._committing) {
|
|
||||||
while (this._idleFuncs.length > 0) {
|
|
||||||
const f = this._idleFuncs.shift();
|
|
||||||
f();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}, 0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
setOnUserJoin(cb) {
|
setOnUserJoin(cb) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue