andyrichardson / subscriptionless

GraphQL subscriptions (and more) on serverless infrastructure
MIT License
93 stars 3 forks source link

Clean up thrown error on disconnect #5

Open andyrichardson opened 3 years ago

andyrichardson commented 3 years ago

Changes

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 ```js 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); } ```