Page Menu
Home
Phorge
Search
Configure Global Search
Log In
Files
F33222241
D14389.1768558371.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Size
3 KB
Referenced Files
None
Subscribers
None
D14389.1768558371.diff
View Options
diff --git a/lib/actions/user-actions.js b/lib/actions/user-actions.js
--- a/lib/actions/user-actions.js
+++ b/lib/actions/user-actions.js
@@ -96,13 +96,13 @@
import { authoritativeKeyserverID } from '../utils/authoritative-keyserver.js';
import { getConfig } from '../utils/config.js';
import { getMessageForException } from '../utils/errors.js';
+import { promiseWithTimeout } from '../utils/promises.js';
import { useDispatchActionPromise } from '../utils/redux-promise-utils.js';
import { useSelector } from '../utils/redux-utils.js';
import {
usingCommServicesAccessToken,
useIsRestoreFlowEnabled,
} from '../utils/services-utils.js';
-import sleep from '../utils/sleep.js';
const loggedOutUserInfo: LoggedOutUserInfo = {
anonymous: true,
@@ -134,13 +134,11 @@
let response = null;
try {
- response = await Promise.race([
+ response = await promiseWithTimeout(
callKeyserverEndpoint('log_out', requests),
- (async () => {
- await sleep(500);
- throw new Error('keyserver log_out took more than 500ms');
- })(),
- ]);
+ 500,
+ 'keyserver log_out',
+ );
} catch {}
const currentUserInfo = response ? loggedOutUserInfo : null;
return { currentUserInfo, preRequestUserState, keyserverIDs };
@@ -223,13 +221,11 @@
};
}
try {
- await Promise.race([
+ await promiseWithTimeout(
callIdentityClientLogOut(),
- (async () => {
- await sleep(500);
- throw new Error('identity log_out took more than 500ms');
- })(),
- ]);
+ 500,
+ logOutType + ' identity log_out',
+ );
} catch {}
})();
@@ -310,13 +306,11 @@
throw new Error('Identity service client is not initialized');
}
try {
- await Promise.race([
+ await promiseWithTimeout(
identityClient.logOut(),
- (async () => {
- await sleep(500);
- throw new Error('identity log_out took more than 500ms');
- })(),
- ]);
+ 500,
+ 'identity log_out',
+ );
} catch {}
return {
currentUserInfo: null,
@@ -662,13 +656,11 @@
? identityClient.deletePasswordUser(password)
: identityClient.deleteWalletUser();
- await Promise.race([
+ await promiseWithTimeout(
deleteUserPromise,
- (async () => {
- await sleep(callIdentityServiceTimeout);
- throw new Error('identity delete user call took more than 500ms');
- })(),
- ]);
+ callIdentityServiceTimeout,
+ 'identity delete user call',
+ );
return {
currentUserInfo: null,
diff --git a/lib/utils/promises.js b/lib/utils/promises.js
--- a/lib/utils/promises.js
+++ b/lib/utils/promises.js
@@ -1,5 +1,7 @@
// @flow
+import sleep from './sleep.js';
+
type Promisable<T> = Promise<T> | T;
async function promiseAll<T: { +[key: string]: Promisable<mixed> }>(
@@ -39,4 +41,23 @@
})();
}
-export { promiseAll, promiseFilter, ignorePromiseRejections };
+function promiseWithTimeout<T>(
+ promise: Promise<T>,
+ timeout: number,
+ promiseDescription: string,
+): Promise<T> {
+ return Promise.race([
+ promise,
+ (async () => {
+ await sleep(timeout);
+ throw new Error(`${promiseDescription} timed out after ${timeout}ms`);
+ })(),
+ ]);
+}
+
+export {
+ promiseAll,
+ promiseFilter,
+ ignorePromiseRejections,
+ promiseWithTimeout,
+};
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Fri, Jan 16, 10:12 AM (17 h, 35 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
5943506
Default Alt Text
D14389.1768558371.diff (3 KB)
Attached To
Mode
D14389: [lib] Create a timeout helper
Attached
Detach File
Event Timeline
Log In to Comment