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

feat: add message queue to WebSocket class #24

Closed

Conversation

hamed-rezaee
Copy link

@hamed-rezaee hamed-rezaee commented Aug 3, 2023

WebSocket Client - Message Queue Feature

This pull request adds a message queue feature to the WebSocket class to handle message queuing and ensure messages are sent in the correct order when the WebSocket connection is not yet established. The message queue stores messages that need to be transmitted to the server over the WebSocket connection until the connection is ready.

Changes Made

  • Added a new private list _messageQueue to store enqueued messages.
  • Modified the send method to enqueue messages when the WebSocket is not connected and send them immediately when the WebSocket is connected.
  • Created a new private method _sendQueuedMessages to process and send messages from the queue when the WebSocket is connected.
  • Modified the _connect method to call _sendQueuedMessages after establishing the WebSocket connection to send any enqueued messages.

Reasoning

The addition of the message queue ensures that messages are sent in the order they were queued once the WebSocket connection is established. This improves the reliability and consistency of the WebSocket client, preventing potential issues with message order and avoiding unresponsive behavior when sending messages before the connection is ready.

Type of Change

  • ✨ New feature (non-breaking change which adds functionality)
  • 🛠️ Bug fix (non-breaking change which fixes an issue)
  • ❌ Breaking change (fix or feature that would cause existing functionality to change)
  • 🧹 Code refactor
  • ✅ Build configuration change
  • 📝 Documentation
  • 🗑️ Chore

Copy link
Owner

@felangel felangel left a comment

Choose a reason for hiding this comment

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

Thanks for the PR! This will need tests before we can merge it. Do you think you'll have time to write unit tests for the newly added functionality?

@felangel
Copy link
Owner

felangel commented Jun 8, 2024

Closing this for now since it's quite old and missing tests. I'm planning to add buffering in the near future 👍

@felangel felangel closed this Jun 8, 2024
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.

2 participants