mirror of
https://github.com/ether/etherpad-lite.git
synced 2025-04-23 08:56:17 -04:00
collab_client: Move task queue class definition to top of file
This commit is contained in:
parent
0dc66e629e
commit
5f80c3f3c9
1 changed files with 16 additions and 14 deletions
|
@ -38,6 +38,21 @@ class Gate extends Promise {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class TaskQueue {
|
||||||
|
constructor() {
|
||||||
|
this._promiseChain = Promise.resolve();
|
||||||
|
}
|
||||||
|
|
||||||
|
async enqueue(fn) {
|
||||||
|
const taskPromise = this._promiseChain.then(fn);
|
||||||
|
// Use .catch() to prevent rejections from halting the queue.
|
||||||
|
this._promiseChain = taskPromise.catch(() => {});
|
||||||
|
// Do NOT do `return await this._promiseChain;` because the caller would not see an error if
|
||||||
|
// fn() throws/rejects (due to the .catch() added above).
|
||||||
|
return await taskPromise;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/** Call this when the document is ready, and a new Ace2Editor() has been created and inited.
|
/** Call this when the document is ready, and a new Ace2Editor() has been created and inited.
|
||||||
ACE's ready callback does not need to have fired yet.
|
ACE's ready callback does not need to have fired yet.
|
||||||
"serverVars" are from calling doc.getCollabClientVars() on the server. */
|
"serverVars" are from calling doc.getCollabClientVars() on the server. */
|
||||||
|
@ -171,20 +186,7 @@ const getCollabClient = (ace2editor, serverVars, initialUserInfo, pad) => {
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
const serverMessageTaskQueue = new class {
|
const serverMessageTaskQueue = new TaskQueue();
|
||||||
constructor() {
|
|
||||||
this._promiseChain = Promise.resolve();
|
|
||||||
}
|
|
||||||
|
|
||||||
async enqueue(fn) {
|
|
||||||
const taskPromise = this._promiseChain.then(fn);
|
|
||||||
// Use .catch() to prevent rejections from halting the queue.
|
|
||||||
this._promiseChain = taskPromise.catch(() => {});
|
|
||||||
// Do NOT do `return await this._promiseChain;` because the caller would not see an error if
|
|
||||||
// fn() throws/rejects (due to the .catch() added above).
|
|
||||||
return await taskPromise;
|
|
||||||
}
|
|
||||||
}();
|
|
||||||
|
|
||||||
const handleMessageFromServer = (evt) => {
|
const handleMessageFromServer = (evt) => {
|
||||||
if (!pad.socket) return;
|
if (!pad.socket) return;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue