-
Notifications
You must be signed in to change notification settings - Fork 4
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
Improvements for on method & tests #2
base: main
Are you sure you want to change the base?
Conversation
signalrkore/src/commonMain/kotlin/eu/lepicekmichal/signalrkore/HubConnection.kt
Outdated
Show resolved
Hide resolved
signalrkore/src/commonMain/kotlin/eu/lepicekmichal/signalrkore/HubConnection.kt
Outdated
Show resolved
Hide resolved
Wow, great work, really appreciated! Thank you! |
Huh you are really fast :) Thank you for implementing the requested feature, I didn't expect that you would implement it so quickly. I did had a look at your changes and I have some points that I would like to point out:
This is most likely done unintentionally as
With inline functions it would be possible to do something like this:
the above code does not compile as the compiler doesn't know which overload to use. In order to solve the issue, we need to change it to the following to return an integer:
Similar is for callback with one parameter and no return value. Example that does not compile do to ambiguity:
the corrected version that works:
Both limitations are only syntax related, so not important for me. If you are aware of these limitations and are fine for you, then ignore this point.
This one is important for me, as I do have scenarios where I need to return the result from a suspend function, and I don't want to use
For me it doesn't matter which approach is implemented, the most important thing is that we have the ability to return results from suspend functions without having to block the current thread. |
…-results # Conflicts: # signalrkore/src/commonMain/kotlin/eu/lepicekmichal/signalrkore/HubCommunication.kt # signalrkore/src/commonMain/kotlin/eu/lepicekmichal/signalrkore/HubConnection.kt # signalrkore/src/commonMain/kotlin/eu/lepicekmichal/signalrkore/HubMessage.kt
signalrkore/src/commonMain/kotlin/eu/lepicekmichal/signalrkore/HubCommunication.kt
Outdated
Show resolved
Hide resolved
I've resolved the conflicts and applied the fix for the first point (register more than one handler without a return value). |
Yesterday I published a quick hotfix regarding your 1. The rest I'm thinking I'll do properly tomorrow.
|
…-results # Conflicts: # signalrkore/src/commonMain/kotlin/eu/lepicekmichal/signalrkore/HubCommunication.kt
I merged the latest master and updated the title and description to reflect the current changes located in this PR.
There is no need to use |
Well, yes and no. If you look at your changes, you'll notice there is one inline function missing. The one without any parameters and that one will be conflicting on JVM. It is just one, but I could argue it is the most important one. The one that is reacting on server's ask with no parameters needed - as in "hey you still there? yes." Hence why I have to think of a way out of it or just introduce onWithResult. |
Ignore the above comment, I've reverted the change as it does not work due to ambiguity, what a pity. UPDATE: The only solution that seems to work, is by adding the following inline functions outside the
then the following code works fine:
but you have to import the |
I have decided to go for onWithResult naming. Mainly for reasons:
I'll push a new version over this weekend. P.S.: Back to your "suspend callback problem". I fully intend to make it suspend, (already made commits of bigger refactoring), but is there a reason not to use the "Flow" variant since you obviously are well-versed in coroutines world? I might make more adjustments if there are some usecases I am not aware of. |
With the Flow variant, it is not possible to respond back to the server because two pieces are missing:
Here is an example with the Flow variant, where you can better see the missing pieces:
In my opinion, there is no need to extend the Flow variant to support client results if calling suspend methods will be supported with the callback variant. Client results requires to have exactly one handler for each target, which means that most Flow operations (e.g. filtering) are not fit for such cases. |
It took a bit longer but 0.8.0 is published. As for my previous comment, I went back on it. Instead, I preferred consistency. As for conflicting overloads, they got suffixed on JVM ( Please let me know if the current version is to your liking. As for your pull request, there are still tests left. I was looking at them and I am unsure of how much they are copied/inspired by official java library. Are they? I am trying to avoid using their code as much as possible, therefore reluctant to accept the PR. |
- Added the ability to use the `on` method with a callback also for `Unit` result type - Move the logic for sending `Client did not provide a result.` before the message is emitted - Perform the `resultProviderRegistry.contains` check when `on` method is called - Always include the catched exception when rethrowing `RuntimeException` - Simplify tests by using a base class and Unconfined dispatcher
Thanks for the new release, overall looks very good! I had to do some changes when merging the latest changes as some tests did fail. It would be nice if these changes would be included in a future release to better match the official client behavior. Let me explain them one by one:
with the above registration we gain the following benefits in comparison of using the
All the above points are addressed with the latest commit in this PR.
The ported tests do test the same use cases as tests in the official library, but were rewritten to use Kotlin Flows instead of Example 1 (on method): Official library test: Ported test: SignalRKore/signalrkore/src/commonTest/kotlin/eu/lepicekmichal/signalrkore/OnTest.kt Lines 12 to 30 in 6c81385
Example 2 (onWithResult method): Official library test : Ported test: SignalRKore/signalrkore/src/commonTest/kotlin/eu/lepicekmichal/signalrkore/OnWithResultTest.kt Lines 12 to 28 in 6c81385
It is not possible to use their code directly as it is written in Java and they are using |
Thanks, I like your changes this time around.
As for tests. As for your PR |
That is fine for me, but if I would have the ability to choose between the following approaches:
and
I would choose the second approach every time :)
Fair point. I am looking forward to see how the rewritten tests will look like :)
I created a separate PR for the mentioned points (#3) |
…-results # Conflicts: # signalrkore/src/commonMain/kotlin/eu/lepicekmichal/signalrkore/HubCommunicationLink.kt
Out of curiosity, I did check how the official C# client implemented the |
This PR contains the following improvements:
on
methods with a callback for simpler usage (e.g.on("add", myMethod)
)on
overload with a callback and no parameterson
methods with a callback and no return value (now exceptions will not stop executing other handlers)on
methods from the Java libraryon
methods to take a suspend callback