pdegand
10/25/2018, 9:17 AMlouiscad
10/25/2018, 9:49 AMJoris PZ
10/25/2018, 1:48 PMclass XYZ
and class BlockingXYZ
?)
• Provide a single API class with both suspending and blocking versions of my methods, i.e. suspend fun doABC()
and fun doABCBlocking()
Are any of these choices considered idiomatic? Or should I just do what feels right to me?bootstraponline
10/25/2018, 2:49 PMMartin Devillers
10/25/2018, 4:52 PM@Test
fun test() = runBlocking {
assertTrue(actor<Unit> { for (it in this) { } }.offer(Unit))
}
But this test passes:
@Test
fun test() = runBlocking {
val actor = GlobalScope.actor<Unit> { for (it in this) { } }
delay(100)
assertTrue(actor.offer(Unit))
}
It’s like the actor’s queue needs some time to be set up. It’s not ready right away after creation.Martin Devillers
10/25/2018, 4:55 PMstart = CoroutineStart.UNDISPATCHED
, but that feels a bit weirddave08
10/25/2018, 5:43 PMimport kotlinx.coroutines.experimental.channels.Channel
import kotlinx.coroutines.experimental.channels.actor
import kotlinx.coroutines.experimental.channels.consumeEach
import kotlinx.coroutines.experimental.runBlocking
import kotlinx.coroutines.experimental.*
fun main(args: Array<String>) = runBlocking {
val progressNotifier = actor<Long>(<http://Dispatchers.IO|Dispatchers.IO>) {
consumeEach {
println(it.toString())
}
}
val progressMapper = actor<Int>(<http://Dispatchers.IO|Dispatchers.IO>) {
for (it in channel) {
progressNotifier.offer(it.toLong())
}
}
(0..5).forEach {
progressMapper.offer(it)
}
progressMapper.close()
}
itnoles
10/25/2018, 11:10 PMuhe
10/26/2018, 9:53 AMsindrenm
10/26/2018, 11:28 AMjava.lang.NoClassDefFoundError: Failed resolution of: Lkotlinx/coroutines/experimental/BuildersKt;
zjuhasz
10/26/2018, 1:02 PMsuspend fun main()
could start a single threaded dispatcher which would be the main dispatcher.
You can make your own single threaded dispatcher for applications but it's a problem for libraries. Libraries can't safely use Dispatchers.Main
because there is no gaurentee there will be an implementation in a users application. A library developer could require there to be an implementation of Dispatcher.Main meaning that if the user wasn't making a UI app they would have to provide their own implementation, but that seems to go against the docs.
Also the documentation doesn't even say the main dispatcher must be single threaded, so it couldn't really be used as a home for operations that aren't thread safe anyway.Jonathan
10/26/2018, 3:35 PMsuspend fun foo(): Int
should be preferred to fun foo(): Deferred<Int>
. Wouldn't it be nice if the IDE would show warning when the result of a function is a deferred? It could help newcomers.Nikky
10/26/2018, 5:21 PMmp
10/26/2018, 6:50 PMlaunch {}
what I want in 0.25.0 to make a coroutine that runs entirely disconnected from the coroutine executing the request handling logic?darkmoon_uk
10/27/2018, 7:14 AMFelix
10/27/2018, 1:51 PMgroostav
10/29/2018, 2:12 AMkotlinx..Channel
?louiscad
10/29/2018, 9:39 AMSangeet
10/29/2018, 11:09 AMCoroutineExceptionHandler
to catch exception that is written inside a function. While calling that function again it is actually throwing previous Exception without executing any coroutines inside that. Can anybody help me with this.dave08
10/29/2018, 12:34 PMcoroutineScope
doesn't return until it completes... but then, I'd need to pass the CoroutineScope in download(scope: CoroutineScope)
? That's a bit messy... and I can't even use a receiver since it's declared on another object... (unless I use with
... 😒)dekans
10/29/2018, 4:27 PMjcechace
10/29/2018, 4:56 PMasync
calls into coroutineScope {}
to inherit the coroutine scope from the calling function (e.g. main)?Steven McLaughlin
10/29/2018, 6:03 PMrunBlocking {
things.forEach {
launch {
doTheThing(it)
}
}
}
I wasn't sure if that was part of the base language now or not. I think I'm just a little confused about where the lines are drawn for thisbdawg.io
10/29/2018, 6:22 PMe: org.jetbrains.kotlin.util.KotlinFrontEndException: Exception while analyzing expression at (20,26) in /path/to/ModuleCommand.kt
Caused by: java.lang.AssertionError: Rewrite at slice FUNCTOR key: @kotlin.internal.InlineOnly public inline fun check(value: kotlin.Boolean, lazyMessage: () -> kotlin.Any): kotlin.Unit defined in kotlin[DeserializedSimpleFunctionDescriptor@2e20f454] old value: org.jetbrains.kotlin.contracts.model.functors.SubstitutingFunctor@7b9036fb@2073048827 new value: org.jetbrains.kotlin.contracts.model.functors.SubstitutingFunctor@5779296b@1467558251
Caused by: java.lang.Throwable: Rewrite at slice FUNCTOR key: @kotlin.internal.InlineOnly public inline fun check(value: kotlin.Boolean, lazyMessage: () -> kotlin.Any): kotlin.Unit defined in kotlin[DeserializedSimpleFunctionDescriptor@2e20f454] old value: org.jetbrains.kotlin.contracts.model.functors.SubstitutingFunctor@7b9036fb@2073048827 new value: org.jetbrains.kotlin.contracts.model.functors.SubstitutingFunctor@5779296b@1467558251
Where position (20, 26) is a kotlinx.coroutines.runBlocking
call import kotlinx.coroutines.runBlocking
11: object ModuleCommand : CliktCommand(...) {
...
20: override fun run() = runBlocking {
...
50: }
...
63: }
I still get this error after performing a Gradle clean. Has anyone experience this type of issue that figured out a fix?bdawg.io
10/29/2018, 6:27 PMcheck
call inside of my functions. By commenting that line out, the code fully compiled. it appears to be an issue with inline function rewriting rather than coroutines itself
The check
call before (fails to compile): val path: String
val group: String
check(File("$path/src/main/kotlin/${group.replace(".", File.separator)}").mkdirs()) { "Failed to create directories for module" }
jcechace
10/29/2018, 7:26 PMCouroutineScope
what if the coroutine is a method inside class? How is this going to behave?
class Watcher {
fun CoroutineScope.watcherStarted() = async {
}
}
Nikky
10/29/2018, 7:31 PMwith(watcher) { watcherStarted() }
@jcechacethevery
10/29/2018, 7:54 PMivan.savytskyi
10/29/2018, 11:58 PMfun main(vararg args: String) = runBlocking {
try {
val deferred = async {
println("Throwing exception from async")
throw ArithmeticException() // Nothing is printed, relying on user to call await
}
deferred.await()
println("Unreached")
} catch (e: ArithmeticException) {
println("Caught ArithmeticException")
}
}
nemi
10/30/2018, 12:11 AM> To ensure a smooth migration, we’ll add a compatibility layer in 1.3 and the classes for experimental coroutines will still remain in the standard library. The compiled Kotlin/JVM code that uses experimental coroutines from 1.1 or 1.2 would still continue to work in Kotlin 1.3.If I’m reading this libs complied experimental coroutines should still work. However that doesn’t seem to be the case. Is there a compiler flag that needs to be set or a separate artifact to be included that I’m not aware of
nemi
10/30/2018, 12:11 AM> To ensure a smooth migration, we’ll add a compatibility layer in 1.3 and the classes for experimental coroutines will still remain in the standard library. The compiled Kotlin/JVM code that uses experimental coroutines from 1.1 or 1.2 would still continue to work in Kotlin 1.3.If I’m reading this libs complied experimental coroutines should still work. However that doesn’t seem to be the case. Is there a compiler flag that needs to be set or a separate artifact to be included that I’m not aware of
Dmytro Danylyk
10/30/2018, 11:23 AMVsevolod Tolstopyatov [JB]
10/30/2018, 9:21 PMnemi
10/30/2018, 9:39 PMVsevolod Tolstopyatov [JB]
10/31/2018, 8:22 AMkotlinx.coroutines
and Kotlin in a classpath?nemi
11/01/2018, 1:13 AM