Files
Desktop/ts/shims/events.ts
T
Scott Nonnenberg 237e239e05 Remove backbone as a dependency
Co-authored-by: Yash <yash@signal.org>
Co-authored-by: ayumi-signal <143036029+ayumi-signal@users.noreply.github.com>
Co-authored-by: Jamie Kyle <113370520+jamiebuilds-signal@users.noreply.github.com>
Co-authored-by: Fedor Indutny <79877362+indutny-signal@users.noreply.github.com>
Co-authored-by: trevor-signal <131492920+trevor-signal@users.noreply.github.com>
2025-08-11 14:06:34 -07:00

27 lines
847 B
TypeScript

// Copyright 2019 Signal Messenger, LLC
// SPDX-License-Identifier: AGPL-3.0-only
import createTaskWithTimeout from '../textsecure/TaskWithTimeout';
import { MINUTE } from '../util/durations';
import { explodePromise } from '../util/explodePromise';
// Matching Whisper.events.trigger API
// eslint-disable-next-line @typescript-eslint/no-explicit-any
export function trigger(name: string, ...rest: Array<any>): void {
window.Whisper.events.emit(name, ...rest);
}
export const waitForEvent = (
eventName: string,
timeout: number = 2 * MINUTE
): Promise<void> =>
createTaskWithTimeout(
(event: string): Promise<void> => {
const { promise, resolve } = explodePromise<void>();
window.Whisper.events.once(event, () => resolve());
return promise;
},
`waitForEvent:${eventName}`,
{ timeout }
)(eventName);