signal-desktop/ts/util/timeAndLogIfTooLong.ts
Josh Perez 1f2cde6d04
Send edited messages support
Co-authored-by: Fedor Indutnyy <indutny@signal.org>
2023-04-20 09:31:59 -07:00

20 lines
472 B
TypeScript

// Copyright 2023 Signal Messenger, LLC
// SPDX-License-Identifier: AGPL-3.0-only
import * as log from '../logging/log';
export async function timeAndLogIfTooLong(
threshold: number,
func: () => Promise<unknown>,
getLogLine: (duration: number) => string
): Promise<void> {
const start = Date.now();
try {
await func();
} finally {
const duration = Date.now() - start;
if (duration > threshold) {
log.info(getLogLine(duration));
}
}
}