@hakit/core
Version:
A collection of React hooks and helpers for Home Assistant to easily communicate with the Home Assistant WebSocket API.
33 lines (32 loc) • 718 B
JavaScript
const f = {};
function v(t) {
return f[t];
}
function s(t, n) {
f[t] = n;
}
const O = async (t, n, m, r, C, i) => {
const u = v(t), l = (o) => !r || r(i, o.result) === o.cacheKey ? o.result : (f[t] = void 0, O(t, n, m, r, C, i));
if (u)
return u instanceof Promise ? u.then(l) : l(u);
const d = m(C);
return s(t, d), d.then(
// When successful, set timer to clear cache
(o) => {
s(t, {
result: o,
cacheKey: r?.(i, o)
}), setTimeout(() => {
s(t, void 0);
}, n);
},
// On failure, clear cache right away
() => {
s(t, void 0);
}
), d;
};
export {
O as timeCachePromiseFunc
};
//# sourceMappingURL=timeCacheFunctionPromise.js.map