coletz
12/12/2018, 9:52 PMkotlin.native.concurrent.InvalidMutabilityException: mutation attempt of frozen <object>@839b6268
). The whole code is the same. Anyone ever had similar issue?internal expect val ApplicationDispatcher: CoroutineDispatcher
class PokeApi {
private val httpClient = HttpClient()
fun getPokemonList(success: (PokemonList) -> Unit){
GlobalScope.launch(ApplicationDispatcher){
val json: String = httpClient.get {
url("<https://pokeapi.co/api/v2/pokemon/>")
}
val deferred = GlobalScope.async(ApplicationDispatcher) {
JSON.nonstrict.parse(PokemonList.serializer(), json)
}
success(deferred.await())
}
}
}
@Serializable
data class Pokemon(
val name: String,
val url: String
)
@Serializable
data class PokemonList(
val count: Int,
val results: List<Pokemon>
)
thevery
12/12/2018, 10:46 PMpandawarrior
12/13/2018, 3:24 AMmutation attempt of frozen <object>@c4226468
private val client = HttpClient()
fun callSimpleApi() {
try {
launch {
getToolString()
}
} catch (e: Exception) {
sampleView.returnString(e.toString())
}
}
suspend fun getToolString() = client.get<String> {
url("<https://tools.ietf.org/rfc/rfc1866.txt>")
}
Sabrina Namur
12/13/2018, 6:54 AMpandawarrior
12/13/2018, 7:57 AMcoletz
12/13/2018, 8:32 AMthevery
12/13/2018, 8:37 AMlistOf(1, 2, 3).filter { it: Int -> it % 2 == 0 }
Frozen:
listOf(1, 2, 3).filter({ it: Int -> it % 2 == 0 }.freeze())
coletz
12/13/2018, 8:55 AMthevery
12/13/2018, 9:34 AMcoletz
12/13/2018, 9:58 AMthevery
12/13/2018, 10:00 AMcoletz
12/13/2018, 10:03 AMclass PokeApi {
private val httpClient = HttpClient()
fun getPokemonList(success: (PokemonList) -> Unit){
1.log()
GlobalScope.launch(ApplicationDispatcher){
2.log()
val json: String = httpClient.get {
3.log()
url("<https://pokeapi.co/api/v2/pokemon/>")
4.log()
}
5.log()
val deferred = GlobalScope.async(ApplicationDispatcher) {
6.log()
JSON.nonstrict.parse(PokemonList.serializer(), json)
}
7.log()
success(deferred.await())
8.log()
}
}
}
fun Int.log(){
println("========= $this")
}
the crash is after log number 4thevery
12/13/2018, 10:18 AMe5l
12/13/2018, 10:27 AMPatrick Jackson
03/13/2019, 5:19 PMe5l
03/14/2019, 8:16 AMclient
instance freeze(do not create it in global scope or object
singleton)coletz
03/19/2019, 11:04 AMe5l
03/19/2019, 11:06 AM