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

Send API returns a write-only channel #302

Merged
merged 4 commits into from
Sep 16, 2023
Merged

Conversation

gammazero
Copy link
Owner

Description, Motivation and Context

This PR simplifies APIs by removing TrySend and SendCtx, and allows the caller of Send more flexability. More flexibility is provided by a channel as it allows the caller to choose to use it in a select, range loop, etc. when writing a message.

Addresses Issue #291

What is the current behavior?

A message is passed into the blocking Send or non-blocking TrySend, or a message and context is passed into SendCtx.

What is the new behavior?

The Send function returns a write-only message channel. The TrySend and SendCtx functions disappear.

What kind of change does this PR introduce?

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)

This might not be considered a breaking change if Send is considered an internal API used when writing your own router or client implementation using the wamp package. You can see this is the case since all of the examples do not need to change.

Checklist:

  • My code follows the code style of this project.
  • I have added tests to cover my changes.
  • Overall test coverage is not decreased.
  • All new and existing tests passed.
  • My change requires a change to the documentation.
    • I have updated the documentation accordingly.

This simplifies APIs by removing TrySend and SendCtx(), and allowing the caller of Send more flexability, More flexability is provided by a channel as it allows the caller to chose to use it in a select, range loop, etc. when writing a message.
// IsLocal returns true if the session is local.
IsLocal() bool
// Send returns the peer's outgoing message channel.
Send() chan<- Message
Copy link
Collaborator

Choose a reason for hiding this comment

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

I find naming Send confusing. It was clear in previous meaning and value. But looking somewhere in the code at line peer.Send() it is not clear that it returns a channel now. And as the signature is changed (thus making new design incompatible with old behaviour) - maybe we can give it better name? At least smth like SendCh? What do you think?

Copy link
Owner Author

Choose a reason for hiding this comment

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

The reason I left it as Send is because that pairs with the existing Recv function that also returns a channel. If we change Send to something else, then we should also change Recv.

// Recv returns a channel of messages from the peer.
Recv() <-chan Message
// Send returns the peer's outgoing message channel.
Send() chan<- Message

Copy link
Collaborator

Choose a reason for hiding this comment

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

Yeah, I see. While we're making a refactoring and can give better naming for both, I'm ok to keep it as is. So it's up to you: if you agree - let's rename! If no - no problem.

router/dealer.go Show resolved Hide resolved
router/auth/ticket.go Outdated Show resolved Hide resolved
router/auth/crauth.go Outdated Show resolved Hide resolved
gammazero and others added 2 commits September 9, 2023 17:35
Co-authored-by: Konstantin Burkalev <[email protected]>
Co-authored-by: Konstantin Burkalev <[email protected]>
Copy link
Collaborator

@KSDaemon KSDaemon left a comment

Choose a reason for hiding this comment

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

👍🏻 LGTM!

@gammazero gammazero merged commit a0895d8 into v3 Sep 16, 2023
6 checks passed
@gammazero gammazero deleted the send-returns-write-chan branch September 16, 2023 20:30
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