How tasks and nio.run work
masterIn nvim-nio, asynchronous actions are organized into tasks. A task represents a series of async actions running in a single context, backed by a Lua coroutine.
To execute asynchronous code, you must wrap it in an async function and pass it to nio.run. All async functions must be called from within a task.
One key advantage of nvim-nio is that it integrates with Lua's built-in pcall, allowing standard error handling to work as expected without custom wrappers.
local nio = require("nio")
local task = nio.run(function()
nio.sleep(10)
print("Hello world")
end)