Mark
08/07/2020, 1:01 PMdarkmoon_uk
08/07/2020, 3:16 PMkotlinx-coroutines-test:1.3.8-1.4.0-rc
for JS with success?
I get resolution errors.tseisel
08/08/2020, 7:56 AMsuspend fun doWork(progress: (Progress) -> Unit)
2️⃣ fun doWork(): Flow<Progress>
3️⃣ fun doWorkIn(scope: CoroutineScope): StateFlow<Progress>
4️⃣ Anything else (please explain in comments !)janvladimirmostert
08/08/2020, 10:25 AMrnentjes
08/08/2020, 12:39 PMRohan Maity
08/08/2020, 3:20 PMtunnel.pipe.send("LOPI")
tunnel.pipe.asFlow().flowOn(Dispatchers.Main).collect {
tvPUI.text = it.toString()
}
delay(2000)
tunnel.pipe.send("HOLA")
raniejade
08/09/2020, 3:48 AMHakob Vardanyan
08/09/2020, 10:41 AMe: org.jetbrains.kotlin.codegen.CompilationException: Back-end (JVM) Internal error: Couldn't inline method call 'collectInMainBy' into
So why it can’t be inlined?
inline fun <reified T> Flow<T>.collectInMainBy(
crossinline onCollect: suspend (T) -> Unit,
crossinline onFailure: suspend (Throwable) -> Unit = { Timber.e(it, tag) }
) {
onEachCatching(onCollect, onFailure).launchInMain(lifecycleScope)
}
inline fun <reified T> Flow<T>.onEachCatching(
crossinline onEach: suspend (T) -> Unit,
crossinline onFailure: suspend (Throwable) -> Unit
) : Flow<T> {
return onEach {
onEach(it)
}.catch {
onFailure(it)
}
}
fun <T> Flow<T>.launchInMain(scope: CoroutineScope): Job = scope.launch(Dispatchers.Main) {
collect()
}
Call side:
buttonProceed.clicks().collectInMainBy(
onCollect = { viewModel.proceedButtonClicked() }
)
Lukas Lechner
08/10/2020, 8:12 AMfun main() = runBlocking {
val job = launch {
repeat(5) { index ->
println("operation number $index")
ensureActive()
Thread.sleep(100)
}
}
delay(150)
job.cancel()
}
Sudhir Singh Khanger
08/10/2020, 10:53 AMfun home(): Flow<HomeResponse> =
flow { emit(ApiService.home()) }.flowOn(<http://Dispatchers.IO|Dispatchers.IO>)
ViewModel
@ExperimentalCoroutinesApi
fun home() {
viewModelScope.launch {
repository.home()
.onStart { _homeLiveData.postValue(Resource.loading(null)) }
.catch { _homeLiveData.postValue(Resource.error(it.message ?: "", null)) }
.collect { _homeLiveData.postValue(Resource.success(it)) }
}
}
Is there anything built-in in Flow that would ignore the repeated calling of home()
method and let the existing request fail or reach success?Ningappa Moodi
08/10/2020, 11:12 AMRohan Maity
08/10/2020, 12:03 PMPacane
08/10/2020, 6:42 PM// This is in a loop
val e = async {
writeFileToDisk()
}
filesBeingWritten.add(e)
//somewhere else
filesBeingWritten.awaitAll()
Is much slower than this
// This is in a loop
writeFileToDisk()
where writeFileToDisk()
is a suspending function calling
withContext(<http://Dispatchers.IO|Dispatchers.IO>) {
val get = Paths.get(imageFilename)
Files.write(get, bytes)
}
And by "slower" I mean it never seems to even complete..? Is there a limitation / maximum amount of Deferred objects we can await at a same time?Sam Garfinkel
08/10/2020, 8:50 PMdelay
duration of a suspended coroutine from another coroutine?Rechee Jozil
08/10/2020, 11:40 PMvineethraj49
08/11/2020, 12:57 AMlaunch
and listen on a channel? with the launch being on the dispatcher?)Manuel Pérez Alcolea
08/11/2020, 3:44 AMVsevolod Kaganovych
08/11/2020, 11:42 AMDenys
08/12/2020, 3:11 AMviralshah
08/12/2020, 4:23 PMfun processMessages(){
for (message in messages) {
val foo = async {processMessage(message)
val bar = foo.await()? // Is this how we await on a suspending function?
when (bar) {
is Outcome.Error -> {// don't delete message, log error}
is Outcome.Success -> {deleteMessage()}
}
}
}
suspend fun processMessage(message): Outcome<Foo>
sealed class Outcome<out T : Any> {
data class Error(val message: String, val cause: Exception? = null) : Outcome<Nothing>()
data class Success<out T : Any>(val value: T) : Outcome<T>()
}
Canato
08/12/2020, 7:35 PMVincent Williams
08/13/2020, 8:11 PMeygraber
08/13/2020, 9:02 PMContinuation.invokeOnCancellation
will be invoked after resuming, and I've been relying on it for internal cleanup. Is there any way to register a callback for when a continuation resumes, or do I need to handle it manually at all the resume points?turastory
08/14/2020, 1:49 AMsuspend operator
soon or later? I’d like to do something like this:
suspend inline operator fun <T> SuspendableLazy<T>.getValue(thisRef: Any?, property: KProperty<*>): T
= ...
private val value by suspendableLazy { getValue() }
fun test() = println(value)
private suspend fun getValue() { ... }
Lukas Lechner
08/14/2020, 8:09 AMAlexander Schell
08/14/2020, 8:15 AMjava.lang.NoClassDefFoundError: kotlin/coroutines/AbstractCoroutineContextKey
I thought adding kotlinx-coroutines-core to my pom.xml would be enough...?
kotlin: 1.3.72
kotlinx-coroutines-core: 1.3.7 - Also tried it with 1.3.5: Same result...ubu
08/14/2020, 12:35 PM/**
* Every time a new value is emitted from A, it will emit instead the latest value from B.
*/
fun <A, B : Any> Flow<A>.switchToLatestFrom(other: Flow<B>): Flow<B> = flow {
coroutineScope {
val latestB = AtomicReference<B?>()
val outerScope = this
launch {
try {
other.collect { latestB.set(it) }
} catch (e: CancellationException) {
outerScope.cancel(e)
}
}
collect {
latestB.get()?.let { b -> emit(b) }
}
}
}
And verifying its behavior through some tests suite, I can’t get why sometimes (event randomly) the following test fails:
@Test
fun `should emit the latest value from B every time A emits something`() {
val a = flowOf(1, 2, 3).onEach { delay(100) }
val b = flowOf('A', 'B', 'C', 'D').onEach { delay(25) }
runBlocking {
val result = a.switchToLatestFrom(b).toList()
val expected = listOf('C', 'D', 'D')
assertEquals(
expected = expected,
actual = result
)
}
}
java.lang.AssertionError:
Expected :[C, D, D]
Actual :[B, D, D]
Need help! Thanks.vineethraj49
08/14/2020, 1:25 PMzak.taccardi
08/14/2020, 7:09 PM1.4.0
stable?Andrea Giuliano
08/15/2020, 4:04 PMAndrea Giuliano
08/15/2020, 4:04 PM