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

Improved subscribe API #1356

Merged
merged 26 commits into from
Jun 16, 2023
Merged

Improved subscribe API #1356

merged 26 commits into from
Jun 16, 2023

Conversation

cmelchior
Copy link
Contributor

@cmelchior cmelchior commented Apr 19, 2023

This PR adds a new subscribe method making it easier to create subscriptions from queries and query results.

Since the subscribe methods have a high chance of being called from a UI context, they are switching to the dispatcher provided by the AppConfiguration. This required reworking the logic around the dispatcher, as previously it was only used by the KtorNetworkTransport.

Now that it can be used by all Sync APIs that want to delegate things to the background. I didn't want to use the notifier dispatcher since we risked it getting blocked by people trying to update subscriptions.

Due to 2 bugs in Coroutines, I had to bump the minimum supported version to 1.7.0: Kotlin/kotlinx.coroutines#3768

@cmelchior cmelchior changed the title [POC] Improved subscribe API Improved subscribe API Apr 27, 2023
@cmelchior cmelchior marked this pull request as ready for review June 1, 2023 17:25
@cmelchior cmelchior requested review from clementetb and rorbech and removed request for clementetb June 1, 2023 17:25
# Conflicts:
#	CHANGELOG.md
#	packages/test-sync/src/commonTest/kotlin/io/realm/kotlin/test/mongodb/shared/SubscriptionExtensionsTests.kt
Copy link
Contributor

@rorbech rorbech left a comment

Choose a reason for hiding this comment

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

Nice. Only essential thing is whether to collapse the anonymous and named variant like we have for MutableSubscriptionSet.add? Otherwise just shattered some comments here and there.

Copy link
Contributor

@clementetb clementetb left a comment

Choose a reason for hiding this comment

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

Nice 🍾, I have added some minor comments and suggestions.

@@ -320,15 +320,14 @@ class RealmTests {

@Test
@Suppress("invisible_member")
fun writeAfterCloseThrows() = runBlocking {
fun writeAfterCloseThrows() = runBlocking<Unit> {
Copy link
Contributor

Choose a reason for hiding this comment

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

We might consider start using runTest, from kotlinx-coroutines-test.

Christian Melchior added 5 commits June 14, 2023 08:05
# Conflicts:
#	packages/test-sync/src/commonTest/kotlin/io/realm/kotlin/test/mongodb/common/SubscriptionExtensionsTests.kt
# Conflicts:
#	packages/library-sync/src/commonMain/kotlin/io/realm/kotlin/mongodb/internal/AppImpl.kt
@cmelchior
Copy link
Contributor Author

@clementetb I should have addressed all concerns now, making this ready for round 2 🙏

Copy link
Contributor

@clementetb clementetb left a comment

Choose a reason for hiding this comment

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

Looks great, some minor comments.

@@ -30,6 +31,11 @@ import kotlin.reflect.KClass
*/
public interface Subscription {

/**
* An unique id, generated by Realm, that identifies this subscription.
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
* An unique id, generated by Realm, that identifies this subscription.
* A unique id, generated by Realm, that identifies this subscription.

@cmelchior cmelchior merged commit fb127e5 into main Jun 16, 2023
@cmelchior cmelchior deleted the cm/flx-better-subscribe branch June 16, 2023 14:37
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 14, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants