From 82fc4e7aa4379001c4c3cd4282a4e65da48a02d7 Mon Sep 17 00:00:00 2001 From: denihs Date: Tue, 9 Jul 2024 12:25:43 -0400 Subject: [PATCH] - callLoginMethod is an async function now - handle async hooks inside _callOnReconnectAndSendAppropriateOutstandingMethods --- packages/accounts-base/accounts_client.js | 4 ++-- packages/ddp-client/common/livedata_connection.js | 11 +++++------ 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/packages/accounts-base/accounts_client.js b/packages/accounts-base/accounts_client.js index bbe8e08115..249a131f8a 100644 --- a/packages/accounts-base/accounts_client.js +++ b/packages/accounts-base/accounts_client.js @@ -307,7 +307,7 @@ export class AccountsClient extends AccountsCommon { if (this._tokenExpiresSoon(result.tokenExpires)) { this.makeClientLoggedOut(); } else { - this.callLoginMethod({ + return this.callLoginMethod({ methodArguments: [{resume: result.token}], // Reconnect quiescence ensures that the user doesn't see an // intermediate state before the login method finishes. So we don't @@ -396,7 +396,7 @@ export class AccountsClient extends AccountsCommon { if (!options._suppressLoggingIn) { this._setLoggingIn(true); } - this.connection.apply( + return this.connection.applyAsync( options.methodName, options.methodArguments, { wait: true, onResultReceived: onResultReceived }, diff --git a/packages/ddp-client/common/livedata_connection.js b/packages/ddp-client/common/livedata_connection.js index 2bb18d4ab0..b3521dda7d 100644 --- a/packages/ddp-client/common/livedata_connection.js +++ b/packages/ddp-client/common/livedata_connection.js @@ -1789,15 +1789,14 @@ export class Connection { if (msg.offendingMessage) Meteor._debug('For: ', msg.offendingMessage); } - _callOnReconnectAndSendAppropriateOutstandingMethods() { + async _callOnReconnectAndSendAppropriateOutstandingMethods() { const self = this; const oldOutstandingMethodBlocks = self._outstandingMethodBlocks; self._outstandingMethodBlocks = []; self.onReconnect && self.onReconnect(); - DDP._reconnectHook.each(callback => { - callback(self); - return true; + await DDP._reconnectHook.forEachAsync(async callback => { + await callback(self); }); if (isEmpty(oldOutstandingMethodBlocks)) return; @@ -1904,7 +1903,7 @@ export class Connection { } } - onReset() { + async onReset() { // Send a connect message at the beginning of the stream. // NOTE: reset is called even on the first connection, so this is // the only place we send this message. @@ -1977,7 +1976,7 @@ export class Connection { // `onReconnect` get executed _before_ ones that were originally // outstanding (since `onReconnect` is used to re-establish auth // certificates) - this._callOnReconnectAndSendAppropriateOutstandingMethods(); + await this._callOnReconnectAndSendAppropriateOutstandingMethods(); // add new subscriptions at the end. this way they take effect after // the handlers and we don't see flicker.