1
0
mirror of https://github.com/matrix-org/matrix-js-sdk.git synced 2025-11-28 05:03:59 +03:00

Don't poll UI auth again until current poll finishes

On slow networks/servers we were ending up with lots of requests in
flight.
This commit is contained in:
David Baker
2019-06-06 18:31:54 +01:00
parent c18c679b9b
commit ae9bcd6f6c

View File

@@ -115,6 +115,8 @@ function InteractiveAuth(opts) {
this._chosenFlow = null;
this._currentStage = null;
this._polling = false;
}
InteractiveAuth.prototype = {
@@ -147,8 +149,9 @@ InteractiveAuth.prototype = {
* completed out-of-band. If so, the attemptAuth promise will
* be resolved.
*/
poll: function() {
poll: async function() {
if (!this._data.session) return;
if (this._polling) return;
let authDict = {};
if (this._currentStage == EMAIL_STAGE_TYPE) {
@@ -169,7 +172,12 @@ InteractiveAuth.prototype = {
}
}
this.submitAuthDict(authDict, true);
this._polling = true;
try {
await this.submitAuthDict(authDict, true);
} finally {
this._polling = false;
}
},
/**
@@ -221,7 +229,7 @@ InteractiveAuth.prototype = {
* in the attemptAuth promise being rejected. This can be set to true
* for requests that just poll to see if auth has been completed elsewhere.
*/
submitAuthDict: function(authData, background) {
submitAuthDict: async function(authData, background) {
if (!this._resolveFunc) {
throw new Error("submitAuthDict() called before attemptAuth()");
}
@@ -232,7 +240,7 @@ InteractiveAuth.prototype = {
};
utils.extend(auth, authData);
this._doRequest(auth, background);
await this._doRequest(auth, background);
},
/**