Skip to content

Is event-based code possible? #87

Answered by edubart
stefanos82 asked this question in Q&A
Discussion options

You must be logged in to vote

If I wanted to write some code that gets executed asynchronously, like using async / await, how would I do that in Nelua?

Can coroutines be used in such way that could emulate such behavior?

I see three approaches to write asynchronous code:

  • Callback hell (using plain callbacks)
  • Stackless coroutines (async / await in some languages like Javascript/Nim)
  • Stackful coroutines, also known as true coroutines (Lua/Nelua way)

Callback hell you can mostly do in any language, just use callbacks for your asynchronous code, this can work fine and probably is the most efficient way, the problem with it is that the code can become unreadable, and tracking state across state continuations can become…

Replies: 3 comments

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Answer selected by edubart
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants