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

Fix: Listeners not honoring multiple failures for subscription #230

Open
wants to merge 2 commits into
base: next
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 20 additions & 16 deletions languages/javascript/src/shared/Events/index.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -167,22 +167,26 @@ const doListen = function(module, event, callback, context, once, internal=false
reject = rej
})

if (promises.length) {
Promise.all(promises).then(responses => {
resolve(listenerId)
}).catch(error => {
// Promise.all rejects if at least one promise rejects... we don't want that behavior here
// TODO: Do something better than fail silently
if (event === '*') {
resolve(listenerId)
}
else {
// Remove the listener from external list on failure to subscribe
// TODO: Instead of removing, the failed subscription shouldn't be put into the external list
listeners.remove(listenerId)
reject(error)
}
})
// Iterate and resolve/reject through the list of promises sequentially
const templistenerId = listenerId;
if(promises.length) {
promises.reduce((prevPromise, currentPromise) => {
return prevPromise
.then(() => currentPromise)
.then(responses => {
resolve(templistenerId)
})
.catch(error => {
if (event === '*') {
resolve(templistenerId)
}
else {
// Remove the failed listener
doClear(templistenerId, event, context)
reject(error)
}
});
}, Promise.resolve());
}
else {
resolve(listenerId)
Expand Down
Loading