Skip to content

Fix async try#1278

Merged
Perryvw merged 5 commits intomasterfrom
fix-async-try
May 29, 2022
Merged

Fix async try#1278
Perryvw merged 5 commits intomasterfrom
fix-async-try

Conversation

@Perryvw
Copy link
Copy Markdown
Member

@Perryvw Perryvw commented May 29, 2022

Fixed functions not correctly halting after await failed due to rejected promise. Got rid of previous weird rejection handler passing in favor of making Try/Catch blocks their own async blocks where catch is in the .catch of the async awaiter.

Fixes #1272

Example:

            const run = async () => {
                try {
                    await foo();
                    halted = false;
                } catch (err) {
                    caught = 'catch err: ' + err;
                } finally {
                    finallyCalled = true;
                }
            };

Translates to:

      local function run()
          return __TS__AsyncAwaiter(function(____awaiter_resolve)
              local ____try = __TS__AsyncAwaiter(function()
                  __TS__Await(foo(nil))
                  halted = false
              end)
              ____try.finally(
                  ____try,
                  function()
                      finallyCalled = true
                  end
              )
              __TS__Await(____try.catch(
                  ____try,
                  function(____, err)
                      caught = "catch err: " .. tostring(err)
                  end
              ))
          end)
      end

@Perryvw Perryvw merged commit 0924b37 into master May 29, 2022
@Perryvw Perryvw deleted the fix-async-try branch May 29, 2022 18:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Async function throws error in try catch without interruption

2 participants