2021-08-18 20:08:14 +00:00
|
|
|
// Copyright 2021 Signal Messenger, LLC
|
|
|
|
// SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
|
2021-11-11 22:43:05 +00:00
|
|
|
export async function awaitObject<
|
|
|
|
Result extends { [key: string]: unknown }
|
|
|
|
>(settings: {
|
|
|
|
[key in keyof Result]: Promise<Result[key]>;
|
|
|
|
}): Promise<Result> {
|
2021-08-18 20:08:14 +00:00
|
|
|
const keys = Object.keys(settings);
|
|
|
|
const promises = new Array<Promise<unknown>>();
|
|
|
|
for (const key of keys) {
|
|
|
|
promises.push(settings[key as keyof Result] as Promise<unknown>);
|
|
|
|
}
|
|
|
|
|
|
|
|
const values = await Promise.all(promises);
|
|
|
|
|
|
|
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
|
|
const result: any = {};
|
|
|
|
for (const [i, key] of keys.entries()) {
|
|
|
|
result[key] = values[i];
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|