This commit is contained in:
Kismet Hasanaj
2026-05-02 20:07:02 +02:00
parent ce8672e283
commit 34dc9aec52
9428 changed files with 1733330 additions and 0 deletions
+28
View File
@@ -0,0 +1,28 @@
/**
* Calls the given function only when the returned promise-like object is
* awaited. Afterwards, it provides the resolved value synchronously as `value`
* property.
*/ export function createLazyResult(fn) {
let pendingResult;
const result = {
then (onfulfilled, onrejected) {
if (!pendingResult) {
pendingResult = Promise.resolve(fn());
}
pendingResult.then((value)=>{
result.value = value;
}).catch(()=>{
// The externally awaited result will be rejected via `onrejected`. We
// don't need to handle it here. But we do want to avoid an unhandled
// rejection.
});
return pendingResult.then(onfulfilled, onrejected);
}
};
return result;
}
export function isResolvedLazyResult(result) {
return result.hasOwnProperty('value');
}
//# sourceMappingURL=lazy-result.js.map