2
0
mirror of https://github.com/KDE/kdeconnect-android synced 2025-08-31 14:15:14 +00:00

Make null check and (de)initialization atomic

This commit is contained in:
Albert Vaca Cintora
2024-06-04 20:05:58 +02:00
parent 4ae6e50020
commit f03c86c4ae

View File

@@ -283,9 +283,16 @@ class Device : PacketReceiver {
get() = links.isNotEmpty()
fun addLink(link: BaseLink) {
if (sendCoroutine == null) {
launchSendCoroutine()
synchronized(sendChannel) {
if (sendCoroutine == null) {
sendCoroutine = CoroutineScope(Dispatchers.IO).launch {
for (item in sendChannel) {
sendPacketBlocking(item.np, item.callback)
}
}
}
}
// FilesHelper.LogOpenFileCount();
links.add(link)
@@ -313,15 +320,9 @@ class Device : PacketReceiver {
)
if (links.isEmpty()) {
reloadPluginsFromSettings()
sendCoroutine?.cancel(CancellationException("Device disconnected"))
sendCoroutine = null
}
}
private fun launchSendCoroutine() {
sendCoroutine = CoroutineScope(Dispatchers.IO).launch {
for (item in sendChannel) {
sendPacketBlocking(item.np, item.callback)
synchronized(sendChannel) {
sendCoroutine?.cancel(CancellationException("Device disconnected"))
sendCoroutine = null
}
}
}