Conversation
# Conflicts: # src/LuaLib.ts # src/lualib/declarations/global.d.ts
tomblind
left a comment
There was a problem hiding this comment.
It would be good to have tests of throwing errors inside async functions as well as catching them with with try...catch blocks.
Also, while it should work fine, a good test would be awaiting inside of a statement that gets wrapped in an IIFE, like a complex conditional :?.
…perfluous try/catch
tomblind
left a comment
There was a problem hiding this comment.
Was about to approve this when I realized something. This isn't going to play with varargs at all. Currently it will optimize and try to directly use the ellipses. But even if you disable vararg optimzation for async functions, the wrapping of the ellipsis will still occur inside the function expression, which will break. The wrapping of the ellipsis needs to get lifted out somehow.
async function foo(...args: unknown[]) {
console.log(...args);
}function foo(self, ...)
return __TS__AsyncAwaiter(
function()
local args = {...}
print(
table.unpack(args)
)
end
)
endCo-authored-by: Tom <tomblind@users.noreply.github.com>
|
I'm so excited to use this!!! Thank you |
* Initial lualib promise class implementation * First promise tests * More promise tests * Promise class implementation * Implemented Promise.all * Promise.any * Promise.race * Promise.allSettled * fix prettier * Add promise example usage test * Added missing lualib dependencies for PromiseConstructor functions * Immediately call then/catch/finally callbacks on promises that are already resolved * Transform all references to Promise to __TS__Promise * PR feedback * Removed incorrect asyncs * Add test for direct chaining * Add test for finally and correct wrong behavior it caught * Added test throwing in parallel and chained then onFulfilleds * Fixed pull request link in ArrayIsArray lualib comment * Initial async await * Disallow await in top-level scope * Add await rejection test * Give await the correct lualib dependencies * use coroutine.status instead of lastData * Better top level await check * Add tests for async lambdas and throws in async functions * Moved toplevel await check to transformAwaitExpression and removed superfluous try/catch * fix for vararg access in async functions (TypeScriptToLua#1096) Co-authored-by: Tom <tomblind@users.noreply.github.com> Co-authored-by: Tom <26638278+tomblind@users.noreply.github.com> Co-authored-by: Tom <tomblind@users.noreply.github.com>
Implemented support for async/await using generators/yields as explained in this article. The actual implementation is based on the TypeScript polyfill as included in the comments in the lualib source.
Generators and yield are implemented in tstl using coroutines, for now it is not possible to use await at the very top level of your code because that would be outside of coroutines, for now
awaitmust appear in anasyncfunction.