Skip to content

Clean up thrown error on disconnect#5

Open
andyrichardson wants to merge 1 commit intomasterfrom
cleanup-on-disconnect
Open

Clean up thrown error on disconnect#5
andyrichardson wants to merge 1 commit intomasterfrom
cleanup-on-disconnect

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