xoid icon indicating copy to clipboard operation
xoid copied to clipboard

Can the initial function of xoid be asynchronous?

Open 000luna000 opened this issue 2 years ago • 1 comments

// 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)
})

000luna000 avatar Feb 01 '24 05:02 000luna000

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.

onurkerimov avatar Apr 05 '24 08:04 onurkerimov