Ben
08/19/2020, 5:00 PMinterval
in coroutines?jw
08/19/2020, 5:01 PMBen
08/19/2020, 5:01 PMrkeazor
08/20/2020, 7:38 AMshl(Int): UInt' is only available since Kotlin 1.4 and cannot be used in Kotlin 1.3
rkeazor
08/20/2020, 7:39 AMCarrascado
08/23/2020, 4:09 PMursus
08/26/2020, 1:38 PMTolriq
08/26/2020, 1:42 PMCarrascado
08/26/2020, 6:42 PMThe pattern where a coroutine is producing a sequence of elements is quite common. This is a part of producer-consumer pattern that is often found in concurrent code. You could abstract such a producer into a function that takes channel as its parameter, but this goes contrary to common sense that results must be returned from functions.It means something like this?
import kotlinx.coroutines.*
import kotlinx.coroutines.channels.*
suspend fun produceSquares(channel: Channel<Int>) {
for (x in 1..5) channel.send(x * x)
channel.close()
}
fun main() = runBlocking {
val squares: Channel<Int> = Channel()
launch {
produceSquares(squares)
}
for (value in squares) {
println(value)
}
println("Done!")
}
Tower Guidev2
08/28/2020, 8:38 AMext.kotlin_version = "1.4.0"
and I cannot import Coroutine kotlinx.coroutines.channels.actor
. I know Actors were marked as obsolete. Have Complex Actors replaced them?
Did I miss a memo 😉
🤔
My Gradle resembles this:-
api 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.3.9'
api 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.3.9'
pambrose
08/28/2020, 5:49 PM./gradlew dependencies
and I saw this for the kotlin-scriptin-compiler-embeddable jar that I use:
kotlinCompilerPluginClasspath
\--- org.jetbrains.kotlin:kotlin-scripting-compiler-embeddable:1.4.0
+--- org.jetbrains.kotlin:kotlin-scripting-compiler-impl-embeddable:1.4.0
| +--- org.jetbrains.kotlin:kotlin-scripting-common:1.4.0
| | +--- org.jetbrains.kotlin:kotlin-stdlib:1.4.0
| | | +--- org.jetbrains.kotlin:kotlin-stdlib-common:1.4.0
| | | \--- org.jetbrains:annotations:13.0
| | \--- org.jetbrains.kotlinx:kotlinx-coroutines-core:1.3.7
| | +--- org.jetbrains.kotlin:kotlin-stdlib:1.3.71 -> 1.4.0 (*)
| | \--- org.jetbrains.kotlin:kotlin-stdlib-common:1.3.71 -> 1.4.0
| +--- org.jetbrains.kotlin:kotlin-scripting-jvm:1.4.0
| | +--- org.jetbrains.kotlin:kotlin-script-runtime:1.4.0
| | +--- org.jetbrains.kotlin:kotlin-stdlib:1.4.0 (*)
| | \--- org.jetbrains.kotlin:kotlin-scripting-common:1.4.0 (*)
| +--- org.jetbrains.kotlin:kotlin-stdlib:1.4.0 (*)
| \--- org.jetbrains.kotlinx:kotlinx-coroutines-core:1.3.7 (*)
\--- org.jetbrains.kotlin:kotlin-stdlib:1.4.0 (*)
Should I be worried about kotlinx-coroutines-core:1.3.7 being pulled in?ansman
08/31/2020, 3:50 PMJob
is cancelled but still having it be cancelled if the parent job is cancelled. Here is a short snippet showcasing the issue:
val job = launch {
delay(400.milliseconds)
showView()
try {
// Ideally I would like this part to mean job.cancel() has no effect
// but if the parent job is cancelled it should cancel immediatly
withContext(NonCancellable) {
delay(400.milliseconds)
}
} finally {
hideView()
}
}
Luis Munoz
09/04/2020, 5:32 AMSaiedmomen
09/04/2020, 9:12 AMMutableStateFlow
is defined as a function and since obj-c supports generics only for classes you get Any?
in swift :/Glen
09/07/2020, 10:25 AMLukas Lechner
09/08/2020, 6:49 AMkotlinx-coroutines-test
to change and when it will become stable? Thanks!Marc Knaup
09/10/2020, 2:25 PMkevinherron
09/11/2020, 7:57 PMShashank
09/13/2020, 5:57 PMStateFlow
at all? 🤔Tash
09/16/2020, 8:07 PMadvanceTimeBy(...)
needs to be called inside a TestBuilders
runBlockingTest { ... }
.
Can it be used without the TestBuilders
runBlockingTest { … }
?Davide Giuseppe Farella
09/17/2020, 7:36 AMrunBlockingTest
is running on the same injected dispatcher )louiscad
09/17/2020, 3:45 PMansman
09/17/2020, 7:26 PMisDispatchNeeded
to work and I see that it tried to run it directly but it gets caught in DispatchedContinuation<*>.executeUnconfined(...)
because eventLoop.isUnconfinedLoopActive
is true. Is there a sane approach to testing this?ansman
09/17/2020, 7:30 PMansman
09/18/2020, 1:41 AMmyanmarking
09/25/2020, 11:37 AMantonioleiva
09/29/2020, 9:10 AMlaunch
, but of course this is not a good idea, because the latest visible item can change several times before the request is finished, and it will run the request to the same page several times too.
So I used a StateFlow in the ViewModel, which is public and mutable, so that the Activity can modify the value with the latest visible item, and then I collect it in the ViewModel and run the request to the repository. As the next value is not processed until the previous one is processed, it works perfectly. But I'm not sure if I'm "hacking" the system somehow 😅
Here's the code for reference:
recycler.addOnScrollListener(object : RecyclerView.OnScrollListener() {
override fun onScrolled(recyclerView: RecyclerView, dx: Int, dy: Int) {
viewModel.lastVisible.value = layoutManager.findLastVisibleItemPosition()
}
})
init {
viewModelScope.launch {
lastVisible.collect { value ->
repository.checkRequireNewPage(value)
_spinner.value = false
}
}
}
That _spinner
is also a MutableStateFlow that I'm then exposing with a public non mutable property, which I think is the regular use of StateFlow (an equivalent to LiveData). That's why I'm not sure if my other code is right or I'm missing something.mp911de
09/29/2020, 1:54 PMmp911de
09/29/2020, 1:54 PM// for reference:
val api: RedisClusterCommands<String, String> = connection.sync()
val api: RedisClusterAsyncCommands<String, String> = connection.async()
Daniele Segato
10/02/2020, 11:03 AMFlow,shareIn
release?