Skip to content

Conversation

@tanmaykm
Copy link
Member

The subscription look callbacks were getting invoked with the SubscriptionMessage struct. But the docs do not mention that, and seem to suggest that the callback would receive the actual message, which seems natural. The callbacks in tests seem to be expecting the actual message too.

Updated the callback invocation to pass the actual message instead of SubscriptionMessage struct.

The subscription look callbacks were getting invoked with the `SubscriptionMessage` struct. But the docs do not mention that, and seem to suggest that the callback would receive the actual message, which seems natural. The callbacks in tests seem to be expecting the actual message too.

Updated the callback invocation to pass the actual message instead of `SubscriptionMessage` struct.
@jkaye2012
Copy link
Collaborator

Hey there, thanks for the PR.

I think this would be a reasonable addition to the library, but should be added as a new method. Otherwise, this would be a major breaking change to the library that would require a new major version and new releases.

@tanmaykm tanmaykm mentioned this pull request Nov 27, 2023
@tanmaykm
Copy link
Member Author

Fair enough.
Maybe we could have subscribe take an optional kwarg that indicates the nature of the function it is registering, and it can then wrap the supplied function accordingly?

How about:

@enum CallbackType  CallbackMsgStruct = 1 CallbackMsgData = 2

function subscribe(conn::SubscriptionConnection, channel::AbstractString, callback::Function; callback_type::CallbackType=CallbackMsgStruct)
...
end

function subscribe(conn::SubscriptionConnection, subs::Dict{AbstractString, Union{Function, Pair{Function,CallbackType}})
...
end

@jkaye2012
Copy link
Collaborator

Generally speaking, I prefer to follow "each method does one thing" rather than giving methods dynamic behavior based on their arguments.

I think the enum is reasonable and should be stored "behind the scenes" (probably along with the callback) to denote which behavior the user wants. With the current storage, this information would be completely erased since only the raw functions are stored.

If we leave the existing methods unchanged and add new ones:

function subscribe_data(conn::SubscriptionConnection, channel::AbstractString, callback::Function)
function subscribe_data(conn::SubscriptionConnection, subs::Dict{AbstractString, Function})

Then, with corresponding documentation I think things will be really easy for users to follow and the code within the library should be clearer as well!

@tanmaykm
Copy link
Member Author

Yes, that sounds good. I have made some changes and added the subscribe_data method.

@jkaye2012
Copy link
Collaborator

This looks good to me. We can merge it and then bring in your CI changes before cutting a new version!

@jkaye2012 jkaye2012 merged commit bd58eda into master Nov 27, 2023
@tanmaykm tanmaykm mentioned this pull request Dec 4, 2023
tanmaykm added a commit that referenced this pull request Dec 4, 2023
- reduce specialization of `psubscribe` signature
- fix typo in call to `_psubscribe`
- introduced `psubscribe_data` similar to what was done in #95

depends on #100
fixes #101
tanmaykm added a commit that referenced this pull request Dec 4, 2023
- reduce specialization of `psubscribe` and `subscribe` method signatures
- fix typo in call to `_psubscribe`
- introduced `psubscribe_data` similar to what was done in #95
- improve tests for `psubscribe` and `subscribe`

depends on #100
fixes #101
tanmaykm added a commit that referenced this pull request Dec 11, 2023
- reduce specialization of `psubscribe` and `subscribe` method signatures
- fix typo in call to `_psubscribe`
- introduced `psubscribe_data` similar to what was done in #95
- improve tests for `psubscribe` and `subscribe`

depends on #100
fixes #101
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