promisary
Version:
A growing collection of utilities to make working with Promises easier and cleaner.
16 lines (15 loc) • 494 B
JavaScript
export async function hashSettled(obj) {
if (obj == null)
return {};
const entries = Object.entries(obj);
const settledEntries = await Promise.all(entries.map(async ([key, value]) => {
try {
const resolved = await value;
return [key, { state: 'fulfilled', value: resolved }];
}
catch (error) {
return [key, { state: 'rejected', reason: error }];
}
}));
return Object.fromEntries(settledEntries);
}