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

Stop using Bluebird.delay and Bluebird promise::delay

Signed-off-by: Michael Telatynski <7t3chguy@gmail.com>
This commit is contained in:
Michael Telatynski
2019-11-21 10:05:59 +00:00
parent 2ce106382a
commit 549b0f9313
4 changed files with 12 additions and 4 deletions

View File

@@ -19,6 +19,7 @@ limitations under the License.
"use strict"; "use strict";
const PushProcessor = require('./pushprocessor'); const PushProcessor = require('./pushprocessor');
import {sleep} from './utils';
/** /**
* This is an internal module. See {@link MatrixClient} for the public class. * This is an internal module. See {@link MatrixClient} for the public class.
@@ -3221,7 +3222,7 @@ MatrixClient.prototype.scrollback = function(room, limit, callback) {
const self = this; const self = this;
// wait for a time before doing this request // wait for a time before doing this request
// (which may be 0 in order not to special case the code paths) // (which may be 0 in order not to special case the code paths)
Promise.delay(timeToWaitMs).then(function() { sleep(timeToWaitMs).then(function() {
return self._createMessagesRequest( return self._createMessagesRequest(
room.roomId, room.roomId,
room.oldState.paginationToken, room.oldState.paginationToken,

View File

@@ -31,6 +31,7 @@ import DeviceInfo from './deviceinfo';
import {CrossSigningInfo} from './CrossSigning'; import {CrossSigningInfo} from './CrossSigning';
import olmlib from './olmlib'; import olmlib from './olmlib';
import IndexedDBCryptoStore from './store/indexeddb-crypto-store'; import IndexedDBCryptoStore from './store/indexeddb-crypto-store';
import {sleep} from '../utils';
/* State transition diagram for DeviceList._deviceTrackingStatus /* State transition diagram for DeviceList._deviceTrackingStatus
@@ -763,7 +764,7 @@ class DeviceListUpdateSerialiser {
// this serves as an easy solution for now. // this serves as an easy solution for now.
let prom = Promise.resolve(); let prom = Promise.resolve();
for (const userId of downloadUsers) { for (const userId of downloadUsers) {
prom = prom.delay(5).then(() => { prom = prom.then(sleep(5)).then(() => {
return this._processQueryResponseForUser( return this._processQueryResponseForUser(
userId, dk[userId], { userId, dk[userId], {
master: masterKeys[userId], master: masterKeys[userId],

View File

@@ -49,6 +49,7 @@ import {
newUnexpectedMessageError, newUnexpectedMessageError,
newUnknownMethodError, newUnknownMethodError,
} from './verification/Error'; } from './verification/Error';
import {sleep} from '../utils';
const defaultVerificationMethods = { const defaultVerificationMethods = {
[ScanQRCode.NAME]: ScanQRCode, [ScanQRCode.NAME]: ScanQRCode,
@@ -1834,7 +1835,7 @@ Crypto.prototype.scheduleKeyBackupSend = async function(maxDelay = 10000) {
// requests from different clients hitting the server all at // requests from different clients hitting the server all at
// the same time when a new key is sent // the same time when a new key is sent
const delay = Math.random() * maxDelay; const delay = Math.random() * maxDelay;
await Promise.delay(delay); await sleep(delay);
let numFailures = 0; // number of consecutive failures let numFailures = 0; // number of consecutive failures
while (1) { while (1) {
if (!this.backupKey) { if (!this.backupKey) {
@@ -1868,7 +1869,7 @@ Crypto.prototype.scheduleKeyBackupSend = async function(maxDelay = 10000) {
} }
if (numFailures) { if (numFailures) {
// exponential backoff if we have failures // exponential backoff if we have failures
await Promise.delay(1000 * Math.pow(2, Math.min(numFailures - 1, 4))); await sleep(1000 * Math.pow(2, Math.min(numFailures - 1, 4)));
} }
} }
} finally { } finally {

View File

@@ -708,3 +708,8 @@ module.exports.ensureNoTrailingSlash = function(url) {
return url; return url;
} }
}; };
// Returns a promise which resolves with a given value after the given number of ms
module.exports.sleep = (ms, value) => new Promise((resolve => {
setTimeout(resolve, ms, value);
}));