Skip to content

Conversation

@LouisCAD
Copy link
Contributor

@LouisCAD LouisCAD commented Nov 19, 2025

I tested thoroughly a bunch of cases with all our 3 compatible apps together.

Here they are:

  1. One app responding slower than another one (but before our IPC timeout strikes)
  2. One app never responding (we show the data of the fastest responding app while waiting for the other one)
  3. Apps connecting but never responding in time (shows loading state until the IPC timeout strikes)
  4. All apps responding, but with no new account available
  5. All apps responding, with one newly available account, and one already connected account
  6. One app with one account, another app with a second account, both shown in the visible app, then logout in one of the 7. connected apps, and coming back, the account is properly removed
  7. And the happy path of all apps responding with 1 or 2 new accounts to log in

Worked perfectly for all of these.

// Lazy start to not send an empty list before the first available responds.
val alreadyConnectedEmailsUpdatingJob = launch(start = CoroutineStart.LAZY) {
alreadyConnectedEmailsFlow.collect { alreadyConnectedEmails ->
send(accountsFlow.updateAndGet { it.withAccounts(emptyList(), alreadyConnectedEmails) })
Copy link
Contributor

Choose a reason for hiding this comment

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

What is the usage of the flow here, instead of just using a mutableList ?
Is it because of concurrent write ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Exactly, it's to use the atomic reference capability of MutableStateFlow.

A MutableList would definitely lead to random ConcurrentModificationException being thrown.

kotlin's AtomicReference supports the equivalent updateAndFetch since 2.2.20 (we could also have made it on top of compareAndSet, it's fairly trivial), so after we update our fork of Realm, we could use it instead if we want.

Not sure it provides any performance or readability improvements, but I can do the replacement later on if you want.

@LouisCAD LouisCAD force-pushed the cross-app-login-improvements branch from 180cfe1 to 166f635 Compare November 27, 2025 14:01
@sonarqubecloud
Copy link

@LouisCAD LouisCAD requested a review from FabianDevel November 27, 2025 14:04
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