bloder
11/12/2018, 12:33 PMerror: cannot access HttpResult
kotlin.coroutines.Continuation<? super HttpResult<MyEntity>> p2);
bad class file: HttpResult.class
undeclared type variable: R
Please remove or make sure it appears in the correct subdirectory of the classpath.
I don't know why but byte code could not find my HttResult class (it's a inline class), I don't know if it's a dependency problem, because I'm importing kotlin(v 1.3.0) and coroutines(v 1.0.0) dependencies in two different modules, but I've already tried to change the versions and dependencies but I could not fix it. Do you guys already got a problem like this before?suppoze
11/12/2018, 1:58 PMprivate val queue = Executors.newSingleThreadExecutor()
//...
fun submit(data: Data) {
queue.submit { updateData(data) }
}
? I was thinking about
private val queue = Executors.newSingleThreadExecutor().asCoroutineDispatcher()
// ...
fun submit(data: Data) = runBlocking {
launch(queue) {
updateData(data)
}
}
but it's seems to be running sequentially somehow? Am I doing something wrong?hho
11/12/2018, 2:00 PMJavier
11/12/2018, 2:29 PMJavier
11/12/2018, 2:29 PMhttps://i.imgur.com/RlhpZyq.png▾
zak.taccardi
11/12/2018, 4:46 PM.launch
or .async
, use the Dispatchers.Unconfined
which should help the coroutine finish before your test doesrocketraman
11/12/2018, 10:33 PMspierce7
11/13/2018, 3:10 AMjava.lang.IncompatibleClassChangeError: Class kotlinx.coroutines.io.internal.MutableDelegateContinuation implements non-interface class kotlinx.coroutines.DispatchedTask (declaration of 'kotlinx.coroutines.io.internal.MutableDelegateContinuation'
Alexander
11/13/2018, 10:35 AMktor
http client with nodejs
and found out that Js
engine only works within browser environment. So I took code of js engine and try to adopt it to work with http
module of nodejs. But it uses streams to read data (an example of how to read data: https://nodejs.org/api/http.html#http_http_request_url_options_callback). And I can't figure out how to do it better. Now I pass all data via channel:
class ResponseReader(response: IncommingMessage) {
private val chunksChannel = Channel<ByteArray>(UNLIMITED)
init {
response.on("data") { chunk: Uint8Array ->
chunksChannel.offer(chunk.asByteArray())
}
response.on("end") { ->
chunksChannel.close()
}
}
suspend fun readChunk(): ByteArray? {
return try {
chunksChannel.receive()
} catch (exc: ClosedReceiveChannelException) {
null
}
}
}
With this solution I cannot cancel reading data. Also as I understand it misses a backpressure propagation thus if data arrives faster then we can process it may lead to a huge memory consumption.functionaldude
11/13/2018, 1:46 PMmapAsync
function. The goal here is to process and map the result of every item asynchronously, but I want to cancel all tasks as soon as one of them fail, also I don’t want to cancel the parent scope. What do you think of this example:functionaldude
11/13/2018, 1:46 PMmersan
11/13/2018, 4:19 PMmersan
11/13/2018, 4:20 PMactive
job by defaulttimrijckaert
11/13/2018, 4:49 PMsuspend fun CoroutineScope.foo() : ReceiveChannel<List<Int>> =
produce {
launch {
val cache = cache.getCachedInts()
offer(cache)
}
launch {
val network = network.getNetworkInts
if (network.isNotEmty()) {
cache.cacheInts(network)
}
offer(network)
}
}
I tried runBlocking
but it seems unavaible in MPP?mersan
11/13/2018, 9:11 PMTolriq
11/13/2018, 9:33 PMtateisu
11/13/2018, 9:44 PMgildor
11/14/2018, 7:43 AMtryResumeWithException
?
I understand this behaviour, avoid exception swallowing, but in this particular case looks that this is the only valid optionrook
11/14/2018, 2:48 PMspierce7
11/14/2018, 5:19 PMivan.savytskyi
11/14/2018, 8:17 PMkotlinx.coroutines.AwaitKt#awaitAll
. From KDocs:
Awaits for completion of given deferred values without blocking a thread and resumes normally with the list of values when all deferred computations are complete or resumes with the first thrown exception if any of computations complete exceptionally including cancellation.If I understand that right
resumes with the first thrown exception
. But having this example:
val exceptionHandler = CoroutineExceptionHandler { _, exception ->
println("exception handler $exception")
}
val scope = CoroutineScope(Dispatchers.Default + exceptionHandler)
scope.launch {
val firstCoroutine = async {
delay(300)
println("crashing first coroutine")
throw IllegalArgumentException()
}
val secondCoroutine = async {
try {
delay(700)
println("second coroutine still alive")
} catch (e: Exception) {
println("second coroutine try/catch $e")
}
"Done"
}
try {
awaitAll(firstCoroutine, secondCoroutine)
} catch (e: Exception) {
println("awaitAll try/catch $e")
}
}
I was expecting to see awaitAll try/catch java.lang.IllegalArgumentException
but instead I see awaitAll try/catch kotlinx.coroutines.JobCancellationException: Job is cancelling; job=StandaloneCoroutine{Cancelling}@27e6316a
.
Could someone pls explain this behaviour?maxime
11/15/2018, 1:24 PMasReference()
) is gone, what is the way to go now? Should I use WeakReference
instead, rely on the coroutine state, or trust the current CoroutineScope?irus
11/15/2018, 3:01 PMwithTimeoutOrNull(1000) {
suspendCancellableCoroutine<Unit> { cont ->
cont.invokeOnCancellation {
cont.resumeWithException(CancellationException("Hello!")) // 1
cont.resumeWithException(RuntimeException("Hello!")) // 2
}
}
}
Can't find place in documenation where difference between (1) and (2) describedspierce7
11/15/2018, 10:06 PMkenkyee
11/16/2018, 1:08 AMzak.taccardi
11/16/2018, 1:09 AMgroostav
11/16/2018, 7:12 AM//producer function following conventional (?) coroutine parent-child-ing as per Romans Coroutines part II at kotlinconf 2018
fun CoroutineScope.longRunningProducer(): RecieveChannel<Info> { ... }
//then a user
fun someUser(){
println("started!")
runBlocking {
val selfScope: CoroutineScope = this@runBlocking
val producer: RecieveChannel<Info> = selfScope.longRunningProducer()
for(item in producer){
if(businessLogic(item)) {
//bail!
break;
}
else //...
}
println("almost done!")
}
println("done!")
}
if longRunningProducer
started!
almost done!
because the nestedEventLoop
wont close until its children are done.
What I'd like to have happen is for an abandoned longRunningProducer
coroutine to simply get garbage collected, but I guess that means I gotta be careful with weakReferences
and such, yeah?gildor
11/16/2018, 2:11 PMPaul Woitaschek
11/16/2018, 3:37 PMuli
11/17/2018, 1:56 PMuli
11/17/2018, 1:56 PMghedeon
11/18/2018, 1:04 AMgildor
11/18/2018, 5:29 AMghedeon
11/21/2018, 4:35 PMgildor
11/22/2018, 2:35 AMuli
11/22/2018, 7:39 AM