Tuan Kiet
07/24/2019, 9:50 AMFlow
documentation to this https://github.com/Kotlin/kotlinx.coroutines/blob/master/coroutines-guide.mdursus
07/25/2019, 1:40 AMshow byte code / decompile to java
in AS for coroutine code take forever for you too?
I want to look how synchronous does look in it, but AS completely freezes up on 32gb machinev0ldem0rt
07/25/2019, 2:58 AMahulyk
07/25/2019, 7:47 AMansman
07/25/2019, 2:29 PMahulyk
07/25/2019, 2:47 PMgroostav
07/26/2019, 7:52 AMCLOVIS
07/27/2019, 9:38 AMMohamed Ibrahim
07/27/2019, 11:05 AMMarko Mitic
07/27/2019, 11:14 AMCLOVIS
07/27/2019, 7:25 PMdave08
07/28/2019, 2:47 PMsuspend fun <K: Any, V> AsyncCache.getSuspending(key: K): V {
val outerContext = coroutineContext
return get(key) { k, executor ->
val innerContext = outerContext + Job() + executor.asCoroutineDispatcher()
CoroutineScope(innerContext).async {
loadValue(k) // loadValue is a suspend function defined elsewhere
}.asCompletableFuture()
}.await()
}
dave08
07/28/2019, 2:57 PMcoroutineScope { async(executor.asCoroutineDispatcher()) { ... } }
or is there a difference?CLOVIS
07/28/2019, 5:37 PMCLOVIS
07/28/2019, 6:56 PMAdam Powell
07/28/2019, 7:12 PMCompletableDeferred
to be a better option for just a single value thoughSeri
07/28/2019, 10:49 PMGlobalScope.launch { ... }
?Adam Powell
07/28/2019, 10:53 PMChildCancelledException
mechanism used by scopedFlow
and `channelFlow`/`callbackFlow` before the latter two lose their @ExperimentalCoroutinesApi
status, or otherwise make external cancellation of a `launch`ed child in those scopes behave that way by default?Pablichjenkov
07/28/2019, 11:58 PMsuspended send
waits until the Queue has more capacity available. Or in other words how the send coroutine is informed that the Queue has capacity available.
It is usual although consider a bad practice in Java, to synchronize on a queue monitor and wait for its size to change. Then whatever consuming thread that acquires the monitor will consume some items release the monitor and notify other waiters.
I guess that in coroutines, above mechanics is not used since it blocks/sleeps the waiter
thread. It probably works by re-scheduling another suspend send
coroutine in the executor. Maybe not, maybe it spins lock on the Queue capacity.
Does anyone can explain what happens internally?Marko Mitic
07/29/2019, 12:38 AMAlexander Weickmann
07/29/2019, 8:34 AMobject HttpApi {
private val httpClient = httpClient {
it.followRedirects = false
}
private suspend fun <T> httpClientWithLogin(work: suspend (HttpClient) -> T): T {
httpClient.login()
return work(httpClient)
}
suspend fun someApiMethod(): Result = httpClientWithLogin { client ->
...
}
}
The problem is, that the httpClient might become unusable, e.g. because it is closed for whatever reason. I want to protect against that by recreating the httpClient instance. So I am doing this:
object HttpApi {
private var httpClient = recreateHttpClient()
private fun recreateHttpClient() = httpClient {
it.followRedirects = false
}
private suspend fun <T> httpClientWithLogin(work: suspend (HttpClient) -> T): T {
return try {
httpClient.login()
work(htpClient)
} catch (e: Exception) {
log.error("Recreating HTTP client", e)
httpClient = recreateHttpClient()
throw e
}
}
suspend fun someApiMethod(): Result = httpClientWithLogin { client ->
...
}
}
I don't particularly like it. For one, I am not sure whether I get multi-threading problems with recreateHttpClient. Also, if a call fails, it is not immediately retried. Can this be handled more elegantly with supervisor coroutine scope? How would you approach this scenario?Patrick Jackson
07/29/2019, 5:30 PMzak.taccardi
07/29/2019, 6:42 PMsuspend () -> T
2. Deferred<T>
Vote 1️⃣ for suspend fun () -> T
or 2️⃣ for Deferred<T>
groostav
07/30/2019, 3:03 AMrunBlocking(JavaFx) { runBlocking(JavaFx) { }}
causes deadlock but runBlocking(JavaFx) { runBlocking { }}
does not?myanmarking
07/30/2019, 1:43 PMsuspend fun requestStepsActivity(): List<Something> = suspendCancellableCoroutine { emitter ->
val listener = object : SimpleEventListener() {
override fun onSent() {
emitter.resume(Something)
}
override fun onFailedSending() {
emitter.resumeWithException(RuntimeException())
}
}
try {
someApi.addListener(listener)
someApi.requestData()
} catch (e: Throwable) {
emitter.resumeWithException(e)
} finally {
someApi.removeListener(listener)
}
}
Matej Drobnič
07/30/2019, 1:49 PMemptyFlow<Unit>().collect
, method on the top of the list in IDE's completion will be the internal method that should not be used. At first IntelliJ did not suggest any extension methods to me. I was baffled since all examples just mention to call .collect {}
, but all I got was method marked as internal with documentation saying to not use. Then on subsequent tries, IDE started suggesting extension methods, but it was not transparent process.JoakimForslund
07/30/2019, 2:38 PMandroidTest
target in a mpp, however, stuff like runBlockingTest
and newSingleThreadContext
is not found Am I missing something?jw
07/30/2019, 3:34 PMContinuation
in the same stack frame? or is that just a best-practice thing to avoid blowing the stack?Thomas
07/30/2019, 7:04 PMFatal Exception: java.io.EOFException
at okio.Buffer.skip + 881(Buffer.java:881)
at okio.Buffer.clear + 874(Buffer.java:874)
at okio.RealBufferedSource.close + 462(RealBufferedSource.java:462)
at okio.RealBufferedSource$inputStream$1.close + 450(RealBufferedSource.java:450)
at kotlinx.coroutines.io.jvm.javaio.ReadingKt$toByteReadChannel$2.invokeSuspend + 96(ReadingKt.java:96)
at kotlinx.coroutines.io.jvm.javaio.ReadingKt$toByteReadChannel$2.create(ReadingKt.java:10)
at kotlinx.coroutines.io.CoroutinesKt$launchChannel$job$1.invokeSuspend + 123(CoroutinesKt.java:123)
at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith + 33(BaseContinuationImpl.java:33)
at kotlinx.coroutines.DispatchedTask.run + 241(DispatchedTask.java:241)
at kotlinx.coroutines.scheduling.CoroutineScheduler.runSafely + 594(CoroutineScheduler.java:594)
at kotlinx.coroutines.scheduling.CoroutineScheduler.access$runSafely + 60(CoroutineScheduler.java:60)
at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.run + 740(CoroutineScheduler.java:740)
It contains no references to my own code. This makes it very difficult to fix these exceptions. I already have debug mode enabled for Coroutines. Does anyone here have any suggestions how I could fix something like this?Icaro Temponi
07/30/2019, 7:26 PMprivate fun barcodeFlow(): Flow<Barcode> = callbackFlow {
val onNext: (t: Barcode) -> Unit = { barcode -> offer(barcode) }
val onError: (t: Throwable) -> Unit = { ex -> throw ex }
val disposable = binding
.barcodeView
.drawOverlay()
.getObservable()
.subscribe(onNext, onError)
awaitClose { disposable.dispose() }
}
I just would like to know if the exception thrown inside the onError
lambda will be propagated down the stream of this callbackFlow to be
caught on a subsequent catch operator as expectedIcaro Temponi
07/30/2019, 7:26 PMprivate fun barcodeFlow(): Flow<Barcode> = callbackFlow {
val onNext: (t: Barcode) -> Unit = { barcode -> offer(barcode) }
val onError: (t: Throwable) -> Unit = { ex -> throw ex }
val disposable = binding
.barcodeView
.drawOverlay()
.getObservable()
.subscribe(onNext, onError)
awaitClose { disposable.dispose() }
}
I just would like to know if the exception thrown inside the onError
lambda will be propagated down the stream of this callbackFlow to be
caught on a subsequent catch operator as expectedDominaezzz
07/30/2019, 7:39 PMonError
.Icaro Temponi
07/30/2019, 7:42 PM