Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clean up thrown error on disconnect #5

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

andyrichardson
Copy link
Owner

Changes

  • Calls disconnect message handler on thrown errors
  • Ensures full cleanup of server side connection close

Clean clean-up

Promise.allSettled ensures that as much cleanup as possible is done - even if some fails.

This method might be a requirement for here also where the first thrown error would potentially cause the lambda to shutdown before other (potentially succeeding) promises can be resolved.

Something like this could work
try {
  await Promise.allSettled([
    Promise.resolve("Resolved!"),
    Promise.reject("Rejected!")
  ]).then((r) =>
    r.forEach(({ status, reason }) => {
      if (status === "rejected") {
        throw reason;
      }
    })
  );
} catch (err) {
  console.log(err);
}

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.

1 participant