asad.awadia
12/28/2018, 5:41 PMgo funcs
and put whatever you want in it and let the scheduler deal with itAllan Wang
12/29/2018, 3:36 AMsuspendCancellableCoroutine
and to check for isCancelled
whenever the method can be cancelled and then to throw an exception or call resumeWithException
? Is there any other way in doing this?Sam
12/30/2018, 5:58 PMsimon.vergauwen
12/30/2018, 10:56 PMCoroutineContext
without depending on coroutines-core
but only on what can be found in std-lib
?groostav
12/30/2018, 11:40 PMdiesieben07
12/31/2018, 5:40 PMfun foo(): Deferred<Foo>
vs. suspend fun foo(): Foo
. The code must execute on a specific dispatcher, so I could use withContext
for the suspend
version. It feels to me like suspend
is the cleaner variant. Correct?vnsgbt
12/31/2018, 7:41 PMselect
statement in an actor
?poohbar
01/01/2019, 4:22 PMrunBlocking
is a bridge between the coroutine "world" and normal non-coroutine "world". Are there any other "bridges"? I am looking for runNonBlocking
.Allan Wang
01/01/2019, 11:44 PMlaunch {
val cookie = web.loadLogin { refresh(it != 100) }
L.d { "Login found" }
FbCookie.save(cookie.id)
web.fadeOut(onFinish = {
profile.fadeIn()
this@LoginActivity.launch { loadInfo(cookie) }
})
}
This is inside an android activity, which implements coroutine scope on the main dispatcher. It took me a while to debug, buy if the second launch
was not from the activity scope, but rather a child of the parent launch
, it would never actually run. Fade out is a normal method with a callback, and loadInfo is a suspended function using withContext(Dispatchers.Main)
.
Why is this the case?bdawg.io
01/02/2019, 4:30 PMmbonnin
01/03/2019, 2:43 PMfun sampleProducer(): Channel<Int>{
val channel = Channel<Int>(UNLIMITED)
val thread = Thread {
var i = 0
while(true) {
channel.offer(i++)
Thread.sleep(1000)
}
}
// the bellow doesn't work but it would be nice if it did
channel.doOnCancel {
// terminate the thread
}
thread.start()
return channel
}
@Test
fun main() {
val channel = sampleProducer()
runBlocking {
for (i in 1..5) {
System.out.println("received: ${channel.receive()}")
}
channel.cancel()
// How can I make sure the thread is joined here or very shortly after here ?
}
}
Hello everyone, I'm trying to bridge an existing library and coroutines. The library has a traditional callback API that I would like to expose as a coroutine channel. It's working well but I cannot find a way to propagate the cancellation to the library. The problem is equivalent to the snippet above. Any idea how I could achieve this ?simon.vergauwen
01/03/2019, 7:27 PMDeferred<A>
NonCancelable
by wrapping and awaiting it in a withContext
block like below. And how does its scope get (re)wired correctly? Snippet seems to work although I don't quite understand it.
val def = thisWasPassedToMe()
val result = withContext(NonCancelable) {
def.await()
}
ukohlmeyer
01/03/2019, 9:04 PMFlow
framework is that they can test their concurrency using a single thread and special dispatching. Could someone possibly point me at some classes that I could look at. I would like to see if I could create a similar CoroutineDispatcher/Scope to handle similar functionalitygroostav
01/03/2019, 9:11 PMchannel.isClosedForReceive
because
This declaration is experimental and its usage must be marked with '@kotlinx.coroutines.InternalCoroutinesApi' or '@UseExperimental(kotlinx.coroutines.InternalCoroutinesApi::class)'any help?
jw
01/04/2019, 4:20 PMurls.map { async { loadUrl(it) } }.map { it.await() }
or I think there's awaitAll()
nowbjonnh
01/04/2019, 10:22 PMKulwinder Singh
01/05/2019, 8:01 AMextension
function await
to get document from firestore database. But when i'm using it like below, exception is thrown and my crashesrocketraman
01/05/2019, 3:19 PMwithContext
that never completes. If I remove the withContext
it does run to completion. The problem seems to be my use inside the withContext
block of async(SupervisorJob(coroutineContext[Job])) { ... }
as described in https://github.com/Kotlin/kotlinx.coroutines/issues/763 -- if I change the call to be a straight async
call, then it works fine. Either this is a bug, or I'm not understanding something...Rohit Surwase
01/07/2019, 6:58 AMsuspendable lambdas + continuation + yeild
internally. I have also watched Exploring Coroutines in Kotlin by Venkat Subramariam several times. If Coroutines works the way it explained in the video then isn’t it like a single thread managing to execute multiple tasks depending upon the priority? Can we actually execute multiple tasks simultaneously on a single thread using Coroutines or it will be just managed by that thread? By managing I mean by using suspend + yeild, the thread will finish all tasks but time taken to finish all tasks will be combination of all individual taks.
Can anyone direct me to better understand internals of Coroutines?myanmarking
01/07/2019, 5:44 PMmainScope.launch {
try{
val attr1 = async(<http://dispatchers.IO|dispatchers.IO>) { networkUser.setUserAttrs(userId, mappedServerData.weight).blockingFirst() }catch(){} }
myanmarking
01/07/2019, 5:50 PMmainScore = CoroutineScope(dispatchers.MAIN + job)
i have thisjkbbwr
01/07/2019, 7:57 PMval threadPool = newSingleThreadContext("git-clone-subprocess-pool")
suspend fun clone(urL: String) {
val result = withContext(threadPool) {
async {
val pb = NuProcessBuilder(listOf("/bin/cat"))
val process = pb.start()
process.waitFor(0, TimeUnit.SECONDS)
}
}
val exitcode = result.await()
}
Juan Rada
01/08/2019, 12:27 AMDefaultDispatcher
) as far as I understant, my threads will be busy all the time as suspend
operations will not block them so there is not benefits (in terms of pipeline throughput) from more threads, and actually throughput is expected to decrease bacause of new threads context switching.withoutclass
01/08/2019, 4:04 PMbdawg.io
01/08/2019, 9:55 PMn
concurrent actors are launchedasad.awadia
01/09/2019, 3:22 AMwithoutclass
01/09/2019, 3:57 AMjw
01/09/2019, 3:58 AMSlackbot
01/09/2019, 11:32 AMmaxmello
01/09/2019, 12:43 PMTimer.schedule
(one time delayed execution) with coroutines, is there a better way than just launching a coroutine and calling delay() at the beginning? With structured concurrency, it would be able to get cancelled the same way than with cancelling the Timer, right?maxmello
01/09/2019, 12:43 PMTimer.schedule
(one time delayed execution) with coroutines, is there a better way than just launching a coroutine and calling delay() at the beginning? With structured concurrency, it would be able to get cancelled the same way than with cancelling the Timer, right?altavir
01/09/2019, 12:53 PMmaxmello
01/09/2019, 12:58 PMstreetsofboston
01/09/2019, 1:10 PMvishna
01/09/2019, 1:11 PMTimer.schedule
on Android but rather Handler.postDelayed
maxmello
01/09/2019, 1:48 PM