Fix coroutine scope (#4820)
* Inject the session scope instead of the application scope where it's possible. * Create AppCoroutineScope annotation to let developers explicitly choose the appropriate CoroutineScope when injecting one.
This commit is contained in:
parent
36c7c7ab9b
commit
5f191d9f9c
58 changed files with 172 additions and 72 deletions
|
|
@ -12,6 +12,7 @@ import io.element.android.libraries.androidutils.diff.DiffCacheUpdater
|
|||
import io.element.android.libraries.androidutils.diff.MutableListDiffCache
|
||||
import io.element.android.libraries.androidutils.system.DateTimeObserver
|
||||
import io.element.android.libraries.core.coroutine.CoroutineDispatchers
|
||||
import io.element.android.libraries.di.annotations.SessionCoroutineScope
|
||||
import io.element.android.libraries.matrix.api.core.RoomId
|
||||
import io.element.android.libraries.matrix.api.notificationsettings.NotificationSettingsService
|
||||
import io.element.android.libraries.matrix.api.roomlist.RoomListService
|
||||
|
|
@ -36,7 +37,8 @@ class RoomListDataSource @Inject constructor(
|
|||
private val roomListRoomSummaryFactory: RoomListRoomSummaryFactory,
|
||||
private val coroutineDispatchers: CoroutineDispatchers,
|
||||
private val notificationSettingsService: NotificationSettingsService,
|
||||
private val appScope: CoroutineScope,
|
||||
@SessionCoroutineScope
|
||||
private val sessionCoroutineScope: CoroutineScope,
|
||||
private val dateTimeObserver: DateTimeObserver,
|
||||
) {
|
||||
init {
|
||||
|
|
@ -77,7 +79,7 @@ class RoomListDataSource @Inject constructor(
|
|||
.onEach {
|
||||
roomListService.allRooms.rebuildSummaries()
|
||||
}
|
||||
.launchIn(appScope)
|
||||
.launchIn(sessionCoroutineScope)
|
||||
}
|
||||
|
||||
private fun observeDateTimeChanges() {
|
||||
|
|
@ -88,7 +90,7 @@ class RoomListDataSource @Inject constructor(
|
|||
is DateTimeObserver.Event.DateChanged -> rebuildAllRoomSummaries()
|
||||
}
|
||||
}
|
||||
.launchIn(appScope)
|
||||
.launchIn(sessionCoroutineScope)
|
||||
}
|
||||
|
||||
private suspend fun replaceWith(roomSummaries: List<RoomSummary>) = withContext(coroutineDispatchers.computation) {
|
||||
|
|
|
|||
|
|
@ -701,7 +701,7 @@ class RoomListPresenterTest {
|
|||
),
|
||||
coroutineDispatchers = testCoroutineDispatchers(),
|
||||
notificationSettingsService = client.notificationSettingsService(),
|
||||
appScope = backgroundScope,
|
||||
sessionCoroutineScope = backgroundScope,
|
||||
dateTimeObserver = FakeDateTimeObserver(),
|
||||
),
|
||||
featureFlagService = featureFlagService,
|
||||
|
|
|
|||
|
|
@ -100,7 +100,7 @@ class RoomListDataSourceTest {
|
|||
roomListRoomSummaryFactory = roomListRoomSummaryFactory,
|
||||
coroutineDispatchers = testCoroutineDispatchers(),
|
||||
notificationSettingsService = notificationSettingsService,
|
||||
appScope = backgroundScope,
|
||||
sessionCoroutineScope = backgroundScope,
|
||||
dateTimeObserver = dateTimeObserver,
|
||||
)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue