darkmoon_uk
09/12/2019, 11:02 AMFlow
and associated API's are likely to leave 'experimental'? Is it too bad to admit I've got production code peppered with Experimental annotations? At least I haven't found bugs with it yet! 😅darkmoon_uk
09/12/2019, 1:48 PMigorvd
09/12/2019, 4:29 PMhooliooo
09/12/2019, 8:38 PMsomeSuspendHttpRequestWithKtor
in parallel from the map
call?
suspend fun someCRUDMethod(models: List<MyModel>) {
val myModels = coroutineScope {
async {
models.map { myAPI.someSuspendHttpRequestWithKtor(it.id) }
}
}
val myListOfModels = myModels.await()
....
}
myanmarking
09/13/2019, 12:45 PMclass TestExample {
class Example {
var counter: Int = 0
fun startCounter() {
val coroutineScope = CoroutineScope(Dispatchers.Unconfined)
coroutineScope.launch {
while (counter <= 100) {
counter += 1
delay(100)
}
}
}
}
@Test
fun `test 1`() = runBlockingTest {
val example = Example()
example.startCounter()
Assert.assertEquals(1, example.counter)
advanceTimeBy(150) // fails
// Thread.sleep(150) // works
Assert.assertEquals(2, example.counter)
}
}
Paul Woitaschek
09/14/2019, 7:16 AMvineethraj49
09/14/2019, 9:50 AMBilagi
09/14/2019, 4:44 PMRetrofit 2.6.0
suspend functions doesn’t support null response body types. Is there any work around for this ?scottiedog45
09/14/2019, 6:21 PMliveData
block, do I need to scope it to viewModelScope
, or is that handled automatically? Specifically I’m concerned about cancelling the job, does that still need to be done with this method?
val testLangLiveData : LiveData<String?> = liveData {
viewModelScope.launch {
try {
emit(repository.getUser().data.attributes?.locale)
} catch (e: Exception) {
}
}
}
vineethraj49
09/15/2019, 1:11 PMevery function that is declared as extension on CoroutineScope returns immediately, but performs its actions concurrently with the rest of the program.i.e.,
suspend fun
is a non-blocking, waiting function; while functions declared on CoroutineScope.foo
are non-blocking, “spawn something else concurrently” function;
what is the idiomatic way to do this in a class that already inherits CoroutineScope
?Kroppeb
09/15/2019, 2:27 PMMark
09/16/2019, 8:33 AM"kotlinx.coroutines.channels.ClosedSendChannelException: Channel was closed"
when calling SendChannel.send
(note: I’m using produce
to build the channel). I’ve isolated the cause to be this upgrade. I couldn’t find anything relevant in the release notes: https://github.com/Kotlin/kotlinx.coroutines/releases . Any tips on how to investigate what could be causing this, please?Dico
09/16/2019, 9:15 AMSendChannel.offer
throws instead of returning false
?
If so, why is there not an equivalent that never throws?tseisel
09/16/2019, 10:15 AMTestObserver
to test coroutines Flow
?groostav
09/16/2019, 6:57 PMjava.util.concurrent
or similar to give me this?scottiedog45
09/16/2019, 10:13 PMfun updateUserLang(user: UpdateUser) {
viewModelScope.launch {
try {
val lang = repository.updateUser(user).data.attributes!!.locale
_networkCallSuccess.postValue(Pair(lang!!, true))
} catch (e: HttpException) {
println("error: ${e.localizedMessage}")
}
}
}
rkeazor
09/16/2019, 11:41 PMAdriano Celentano
09/17/2019, 7:54 AMval trace = Thread.currentThread().stackTrace
val handler = CoroutineExceptionHandler { _, throwable ->
throwable.stackTrace += trace
result(Result.failure(throwable))
}
Tuan Kiet
09/17/2019, 8:08 AMviewModelScope.launch{}
but don’t care about the result. When a coroutine is finished, does it goes away or it stays in memory?Colton Idle
09/17/2019, 1:40 PMfun button1Clicked() {
GlobalScope.launch {
Toast.makeText(this@MainActivity, doSomethingLong(), Toast.LENGTH_LONG).show()
}
Toast.makeText(this@MainActivity, "Hello", Toast.LENGTH_LONG).show()
}
suspend fun doSomethingLong(): String =
withContext(Dispatchers.Default) {
delay(3000)
return@withContext "World"
}
dave08
09/17/2019, 3:22 PMCasey Brooks
09/17/2019, 4:54 PMtry {
coroutineScope {
next()
}
} catch (e: Exception) {
if(e !is CancellationException) {
onCancelled()
}
else {
onFailure()
}
}
Seri
09/17/2019, 7:53 PMfun <T> List<Flow<T>>.join() = channelFlow {
for (flow in this@join) {
launch { flow.collect {
send(it)
}}
}
}
Allan Wang
09/17/2019, 11:51 PMAllan Wang
09/18/2019, 12:18 AMnomad
09/18/2019, 11:41 AMMohamed Hamdan
09/18/2019, 9:36 PMzak.taccardi
09/19/2019, 1:35 AM.offer(item)
return false
) if no one is receiving?vineethraj49
09/19/2019, 9:26 AM<http://Dispatchers.IO|Dispatchers.IO>
shares threads with Dispatchers.Default
, is it possible that if there are too many IO requests, coroutines spawned on .Default
will be starved?Kroppeb
09/19/2019, 12:51 PMKroppeb
09/19/2019, 12:51 PMmarstran
09/19/2019, 12:57 PMKroppeb
09/19/2019, 1:04 PMmarstran
09/19/2019, 1:11 PMKroppeb
09/19/2019, 1:11 PMmarstran
09/19/2019, 1:12 PMsuspendCoroutine
function. Check out this article: https://medium.com/@elizarov/callbacks-and-kotlin-flows-2b53aa2525cfPaulius Ruminas
09/19/2019, 1:12 PMKroppeb
09/19/2019, 1:12 PMmarstran
09/19/2019, 1:15 PMsuspend fun ByteChannel.read(): ByteBuffer = suspendCoroutine { continuation ->
read { continuation.resume(it) }
}
Kroppeb
09/19/2019, 1:18 PMmarstran
09/19/2019, 1:49 PMread
isn't suspending, right?readSuspending
?Kroppeb
09/19/2019, 1:50 PMmarstran
09/19/2019, 1:51 PMKroppeb
09/19/2019, 1:51 PMmarstran
09/19/2019, 1:52 PMByteChannel
from?Kroppeb
09/19/2019, 2:04 PMkotlin.coroutines.io.ByteReadChannel#read
Evan R.
09/19/2019, 2:26 PMKroppeb
09/19/2019, 2:34 PMEvan R.
09/19/2019, 2:48 PMread
is a suspending function it will wait until new bytes come into the channel before writing out to the output channel.Colton Idle
09/20/2019, 3:29 AM