From a83642ce3f54050054c042dd83ce5cfce6eafab8 Mon Sep 17 00:00:00 2001 From: "(quasar) nebula" Date: Thu, 2 May 2024 14:16:31 -0300 Subject: sugar: make withEntries work async --- src/util/sugar.js | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'src/util') diff --git a/src/util/sugar.js b/src/util/sugar.js index d0b7ffab..183a75d5 100644 --- a/src/util/sugar.js +++ b/src/util/sugar.js @@ -183,8 +183,14 @@ export const compareArrays = (arr1, arr2, {checkOrder = true} = {}) => : arr1.every((x) => arr2.includes(x))); // Stolen from jq! Which pro8a8ly stole the concept from other places. Nice. -export const withEntries = (obj, fn) => - Object.fromEntries(fn(Object.entries(obj))); +export const withEntries = (obj, fn) => { + const result = fn(Object.entries(obj)); + if (result instanceof Promise) { + return result.then(entries => Object.fromEntries(entries)); + } else { + return Object.fromEntries(result); + } +} export function setIntersection(set1, set2) { const intersection = new Set(); -- cgit 1.3.0-6-gf8a5