mirror of
https://github.com/signalapp/Signal-Desktop.git
synced 2026-05-08 08:58:38 +01:00
Add durations utility for computing durations
This commit is contained in:
@@ -14,6 +14,7 @@ import { strictAssert } from '../util/assert';
|
||||
import { explodePromise } from '../util/explodePromise';
|
||||
import { BackOff, FIBONACCI_TIMEOUTS } from '../util/BackOff';
|
||||
import { getUserAgent } from '../util/getUserAgent';
|
||||
import * as durations from '../util/durations';
|
||||
import { sleep } from '../util/sleep';
|
||||
import { SocketStatus } from '../types/SocketStatus';
|
||||
import * as Errors from '../types/errors';
|
||||
@@ -30,9 +31,9 @@ import { WebAPICredentials, IRequestHandler } from './Types.d';
|
||||
// TODO: remove once we move away from ArrayBuffers
|
||||
const FIXMEU8 = Uint8Array;
|
||||
|
||||
const TEN_SECONDS = 1000 * 10;
|
||||
const TEN_SECONDS = 10 * durations.SECOND;
|
||||
|
||||
const FIVE_MINUTES = 5 * 60 * 1000;
|
||||
const FIVE_MINUTES = 5 * durations.MINUTE;
|
||||
|
||||
export type SocketManagerOptions = Readonly<{
|
||||
url: string;
|
||||
|
||||
@@ -1,12 +1,14 @@
|
||||
// Copyright 2020 Signal Messenger, LLC
|
||||
// SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
import * as durations from '../util/durations';
|
||||
|
||||
export default function createTaskWithTimeout<T, Args extends Array<unknown>>(
|
||||
task: (...args: Args) => Promise<T>,
|
||||
id: string,
|
||||
options: { timeout?: number } = {}
|
||||
): (...args: Args) => Promise<T> {
|
||||
const timeout = options.timeout || 1000 * 60 * 2; // two minutes
|
||||
const timeout = options.timeout || 2 * durations.MINUTE;
|
||||
|
||||
const errorForStack = new Error('for stack');
|
||||
|
||||
|
||||
@@ -30,6 +30,7 @@ import { z } from 'zod';
|
||||
import Long from 'long';
|
||||
|
||||
import { assert, strictAssert } from '../util/assert';
|
||||
import * as durations from '../util/durations';
|
||||
import { getUserAgent } from '../util/getUserAgent';
|
||||
import { toWebSafeBase64 } from '../util/webSafeBase64';
|
||||
import { SocketStatus } from '../types/SocketStatus';
|
||||
@@ -266,7 +267,7 @@ function _validateResponse(response: any, schema: any) {
|
||||
return true;
|
||||
}
|
||||
|
||||
const FIVE_MINUTES = 1000 * 60 * 5;
|
||||
const FIVE_MINUTES = 5 * durations.MINUTE;
|
||||
|
||||
type AgentCacheType = {
|
||||
[name: string]: {
|
||||
|
||||
@@ -27,6 +27,7 @@ import { connection as WebSocket, IMessage } from 'websocket';
|
||||
|
||||
import EventTarget, { EventHandler } from './EventTarget';
|
||||
|
||||
import * as durations from '../util/durations';
|
||||
import { dropNull } from '../util/dropNull';
|
||||
import { isOlderThan } from '../util/timestamp';
|
||||
import { strictAssert } from '../util/assert';
|
||||
@@ -34,7 +35,7 @@ import { normalizeNumber } from '../util/normalizeNumber';
|
||||
import * as Errors from '../types/errors';
|
||||
import { SignalService as Proto } from '../protobuf';
|
||||
|
||||
const THIRTY_SECONDS = 30 * 1000;
|
||||
const THIRTY_SECONDS = 30 * durations.SECOND;
|
||||
|
||||
const MAX_MESSAGE_SIZE = 64 * 1024;
|
||||
|
||||
@@ -385,7 +386,7 @@ export type KeepAliveOptionsType = {
|
||||
|
||||
const KEEPALIVE_INTERVAL_MS = 55000; // 55 seconds + 5 seconds for closing the
|
||||
// socket above.
|
||||
const MAX_KEEPALIVE_INTERVAL_MS = 300 * 1000; // 5 minutes
|
||||
const MAX_KEEPALIVE_INTERVAL_MS = 5 * durations.MINUTE;
|
||||
|
||||
class KeepAlive {
|
||||
private keepAliveTimer: NodeJS.Timeout | undefined;
|
||||
|
||||
Reference in New Issue
Block a user