25 lines
708 B
TypeScript
25 lines
708 B
TypeScript
// Copyright 2021 Signal Messenger, LLC
|
|
// SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
export function explodePromise<T>(): {
|
|
promise: Promise<T>;
|
|
resolve: (value: T) => void;
|
|
reject: (error: Error) => void;
|
|
} {
|
|
let resolve: (value: T) => void;
|
|
let reject: (error: Error) => void;
|
|
|
|
const promise = new Promise<T>((innerResolve, innerReject) => {
|
|
resolve = innerResolve;
|
|
reject = innerReject;
|
|
});
|
|
|
|
return {
|
|
promise,
|
|
// Typescript thinks that resolve and reject can be undefined here.
|
|
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
resolve: resolve!,
|
|
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
reject: reject!,
|
|
};
|
|
}
|