UNPKG

vasille-jsx

Version:

The same framework which is designed to build bulletproof frontends (JSX components)

35 lines (34 loc) 858 B
import { ref } from "./internal.js"; export function awaited(target, createRef = ref) { const err = createRef(undefined); const value = createRef(undefined); let running = false; function run() { if (running) { return; } let current; running = true; err.V = undefined; value.V = undefined; try { current = target(); } catch (e) { current = undefined; err.V = e; } if (current instanceof Promise) { current .then(result => (value.V = result)) .catch(e => (err.V = e)) .finally(() => (running = false)); } else { value.V = current; running = false; } } run(); return [err, value, run]; }