Async/Await with Coroutines
Create async() and await() helpers that yield and resume coroutines.
The Async/Await Idea
Async/await is a programming model where asynchronous operations look like synchronous code. In Lua, coroutines provide the yield/resume mechanism to implement this naturally.
await Function
await(future) yields the current coroutine and stores a callback that resumes it when the future completes.
local function await(future)
local co = coroutine.running()
future.onComplete = function(result)
coroutine.resume(co, result)
end
return coroutine.yield()
endAll lessons in this course
- Building a Simple Event Loop
- Async/Await with Coroutines
- Promise-Like Patterns
- Non-Blocking I/O with luasocket