Skip to content

fix: use correct subscription key in publishAsync#106

Merged
jdesrosiers merged 2 commits intohyperjump-io:mainfrom
justin212407:publishAsync-typeError
Mar 4, 2026
Merged

fix: use correct subscription key in publishAsync#106
jdesrosiers merged 2 commits intohyperjump-io:mainfrom
justin212407:publishAsync-typeError

Conversation

@justin212407
Copy link
Copy Markdown
Contributor

Summary

publishAsync in pubsub.js contained bug where subscriber callbacks were being looked up using the published message key instead of the matched subscribedMessage key.

Both publish and publishAsync iterate over all registered subscription keys and match them against the incoming message using startsWith to support topic prefixes (e.g. a subscriber on "validate" catching "validate.metaValidate"). However, publishAsync incorrectly used subscriptions[message] when invoking the callback instead of subscriptions[subscribedMessage], meaning when the two keys diverged the lookup would target the wrong subscription map returning undefined and throwing a TypeError at runtime.

Result

Wildcard subscriptions now work properly with async events without crashing. The async and sync pub/sub implementations now behave the same way.

Fixes - #105

Signed-off-by: justin212407 <charlesjustin2124@gmail.com>
@animeshsahoo1
Copy link
Copy Markdown

hi @justin212407 here subscribedMessage is equal to the message as you can see in the above line, so I don't think its a bug.

@justin212407
Copy link
Copy Markdown
Contributor Author

@animeshsahoo1 please take a closer look the only difference is that, while subscribedMessage === message in the first condition, the second condition allows for hierarchical matching since it is under an if-else conditional statement.

@animeshsahoo1
Copy link
Copy Markdown

oh yeah true didnt see the 2nd condition

Copy link
Copy Markdown
Collaborator

@jdesrosiers jdesrosiers left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As I mentioned in the issue, please remove the unused code instead. Also, please wait for discussion before creating a PR. The obvious solution may not always be the right solution, so it's worth discussing first.

@justin212407
Copy link
Copy Markdown
Contributor Author

As I mentioned in the issue, please remove the unused code instead. Also, please wait for discussion before creating a PR. The obvious solution may not always be the right solution, so it's worth discussing first.

Apologies, will definitely ensure that a proper discussion is held regarding an issue before i open a PR over from the next time.

Signed-off-by: justin212407 <charlesjustin2124@gmail.com>
Copy link
Copy Markdown
Collaborator

@jdesrosiers jdesrosiers left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good enough. Thanks.

@jdesrosiers jdesrosiers merged commit 47f8b10 into hyperjump-io:main Mar 4, 2026
2 checks passed
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.

3 participants