Skip to content

Add .ready promise to Subscriber #1372

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

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

Conversation

controversial
Copy link

Background: Most commands return a promise that resolves when the command is complete/executed and its result can be relied upon, however .subscribe and .psubscribe return Subscriber instances before the SUBSCRIBE commands have completed their round trip to Redis, so it’s hard to know when the subscription(s) are ready, connected, and listening. This problem can be seen in the tests, which used a 500ms delay to try to ensure that the subscription was ready before sending PUBLISH commands

As an alternative, this PR adds a .ready property to Subscriber which clients can await to know when the subscription(s) are ready, i.e. when it’s safe to start publishing commands.

  • I’m not sure whether .ready is the best name for this promise
  • this is my first contribution so I’m not sure whether there’s anything I’m missing design-wise
  • I updated the tests with the intended usage

for knowing when the subscription commands are complete and listening
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