Marco Dalla Bà
12/22/2022, 11:20 AMclass IPWebSocket() {//...
private val requestQueue: MutableList<IPMessageRequest> = mutableListOf()
//...
fun send(request: IPMessageRequest) {
requestQueue.add(request)
webSocket.sendMessage(request)
scope.launch {
delay(REQUEST_TIMEOUT)
requestQueue.firstOrNull { it == request }?.let {
//Some operations
}
}
}
//...
fun receive(msg: Message) {
val iterator = requestQueue.listIterator()
while (iterator.hasNext()) {
val request = iterator.next()
if (msg.msgid == request.msgid) {
iterator.remove()
}
}
}
}
With the new Native Memory Management, by reading the docs, I understood that I don't need to handle locks on the requestQueue like I was doing before with stately-iso-collection but I'm still getting ConcurrentModificationException on the send function. What I am doing wrong? Note: obviously the send and receive methods can be accessed by multiple threads
EDIT: ok I think I found the problem, we're using kotlin.coroutines "1.6.0-native-mt" and -native-mt should be removed. But I think the app will slow down If I do that.mkrussel
12/22/2022, 1:09 PMMarco Dalla Bà
12/22/2022, 1:32 PMmkrussel
12/22/2022, 2:07 PMmkrussel
12/22/2022, 2:08 PMMarco Dalla Bà
12/22/2022, 2:08 PMPablichjenkov
12/22/2022, 5:27 PMPablichjenkov
12/22/2022, 5:32 PM