1
0
mirror of https://github.com/hotomoe/hotomoe synced 2024-11-28 23:08:17 +09:00
This commit is contained in:
syuilo 2019-04-24 03:26:02 +09:00
parent 4e90fd3a06
commit 701ab6cc68
No known key found for this signature in database
GPG Key ID: BDC4C49D06AB9D69

View File

@ -7,16 +7,17 @@ type AwaitAll<T> = {
export async function awaitAll<T>(obj: T): Promise<AwaitAll<T>> {
const target = {} as any;
const keys = Object.keys(obj);
const rawValues = Object.values(obj);
const retValues = ((values: any[]): any[] =>
values.map(value => {
if (!value || !value.constructor || value.constructor.name !== 'Object') return value;
return awaitAll(value);
})
)(rawValues);
const values = await Promise.all(retValues);
for (let i = 0; i < values.length; i++) {
target[keys[i]] = values[i];
const values = Object.values(obj);
const resolvedValues = await Promise.all(values.map(value =>
(value || !value.constructor || value.constructor.name !== 'Object')
? value
: awaitAll(value)
));
for (let i = 0; i < keys.length; i++) {
target[keys[i]] = resolvedValues[i];
}
return target;
}