mirror of
https://github.com/signalapp/Signal-Desktop.git
synced 2026-04-25 19:08:04 +01:00
Rename files
This commit is contained in:
25
ts/util/wrapEventEmitterOnce.node.ts
Normal file
25
ts/util/wrapEventEmitterOnce.node.ts
Normal file
@@ -0,0 +1,25 @@
|
||||
// Copyright 2022 Signal Messenger, LLC
|
||||
// SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
import type { EventEmitter } from 'node:events';
|
||||
import { once } from 'node:events';
|
||||
|
||||
export async function wrapEventEmitterOnce(
|
||||
emitter: EventEmitter,
|
||||
eventName: string
|
||||
): Promise<ReturnType<typeof once>> {
|
||||
const abortController = new AbortController();
|
||||
const maybeRejection = (async (): Promise<ReturnType<typeof once>> => {
|
||||
const [error] = await once(emitter, 'error', {
|
||||
signal: abortController.signal,
|
||||
});
|
||||
|
||||
throw error;
|
||||
})();
|
||||
|
||||
try {
|
||||
return await Promise.race([maybeRejection, once(emitter, eventName)]);
|
||||
} finally {
|
||||
abortController.abort();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user