Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can the initial function of xoid be asynchronous? #24

Open
0xErick opened this issue Feb 1, 2024 · 1 comment
Open

Can the initial function of xoid be asynchronous? #24

0xErick opened this issue Feb 1, 2024 · 1 comment

Comments

@0xErick
Copy link

0xErick commented Feb 1, 2024

// 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)
})
@onurkerimov
Copy link
Member

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants