|
|
|
|
|
by wruza
3170 days ago
|
|
Js: async function bar(){...}
function baz() {...}
async function foo() {
var x = await bar();
var y = baz();
return x, y;
}
Lua: function bar() return something_that_may_yield_deep_inside(...) end
function baz() ... end
function foo()
local x = bar()
local y = baz()
return x, y
end
Iow, in Lua it is irrelevant whether something yields or not, so you don’t care if it is async. |
|
When I see
I know that other code, outside bar(), may have run during the execution of that statement.Also, the JS approach makes composing asynchronous operations simple:
Both bar invocations can run in parallel. If, say, each invocation of bar fires off an Ajax request that takes a few seconds to come back, that can be a significant saving.It's unclear (to me) how that would be done in Lua without complicating the API.