xoid
xoid copied to clipboard
Can the initial function of xoid be asynchronous?
// From https://www.xoid.dev/docs/performance-optimizations
const $atom = create(() => {
console.log('I am lazily evaluated!')
return expensiveComputation(25)
})
// Is it okay this way?
const $atom = create(async () => {
console.log('I am lazily evaluated!')
return await expensiveComputation(25)
})
Hi @0xErick , thank you for bringing this up. This would be a nice feature, but there isn't such feature yet. I may implement it as a separate helper such as promiseAtom, asyncAtom in the next version.
PS: I will likely won't add it as a side-feature to the create function ever, because detecting if a function is async isn't reliable on some JS runtimes. It'll likely be a different function that looks and feels like create.