spand
10/10/2018, 9:03 AMval scope = GlobalScope + Job()
that is no longer active. If I call scope.launch
the new coroutine will never get a chance to execute but caller of launch
is oblivious to this. Would it not make more sense have a fail fast behaviour akin to Executor.execute
that throws RejectedExecutionException
in a similar situation ?Jonathan
10/10/2018, 9:17 AMtiwiz
10/10/2018, 10:04 AMrunBlocking
behaviour happens even with a possible delay. In the following gist (https://gist.github.com/tiwiz/b85c72fb77148e6cc12aa378b762e94b) there is the code (the delay
is only to test if the test waits or not). So far, we couldn't have it to wait, so we must be doing something wrong... does anyone have a clue about it?rocketraman
10/10/2018, 12:54 PMSequence.map
and flatMap
? These operations on Sequence
are not inlined, unlike List
, so you get the error Suspension functions can only be called within coroutine body
. I don't want to use runBlocking
inside the lambda.poohbar
10/10/2018, 4:21 PMfun <A, B> Sequence<A>.pmap(f: suspend (A) -> B): Sequence<B> = runBlocking {
map { async(Dispatchers.Default) { f(it) } }.map { it.await() }
}
how come this says Suspension function can be called only within couroutine body
on the it.await()
call?serebit
10/10/2018, 5:52 PMdigitalsanctum
10/10/2018, 6:56 PMdelay
?otakusenpai
10/10/2018, 7:27 PMspand
10/11/2018, 6:13 AMclass Activity : CoroutineScope {
var job = Job()
override val coroutineContext: CoroutineContext
get() = Dispatchers.Default + job
init {
val workJob = launch(start = CoroutineStart.LAZY) {
// Doing stuff
delay(5000)
}
launch(start = CoroutineStart.ATOMIC) {
try {
workJob.join()
} finally {
println("Cleaning up")
}
}
}
fun destroy() {
job.cancel()
}
}
David W
10/11/2018, 3:36 PMactor
? Basically I have a redux-ish pipeline where each input may result in 0+ state changes. Not sure how to tell when my pipeline is "inactive".acando86
10/11/2018, 5:07 PMconcatMap
of Rx). Is awaitAll
order-preserving on lists? if not, what's the best way to be non-blocking on the map while keeping the order of the list?Ruckus
10/11/2018, 8:45 PMMutex.tryLock()
always return true? Or does it just not work like ReentrantLock
?Slackbot
10/12/2018, 5:15 AMJan
10/12/2018, 9:13 AMmayojava
10/12/2018, 9:51 AMrunBlocking
and coroutineScope
in the coroutine docs, it says coroutineScope
does not block the current thread while waiting for all its children to complete. Then an example was given that shows otherwise. coroutineScope
actually blocks the thread that runBlocking
was invoked from while waiting for its children to complete. Have I understood this the wrong way?mayojava
10/12/2018, 9:52 AMfun main(args: Array<String>) = runBlocking { // this: CoroutineScope
launch {
delay(200L)
println("Task from runBlocking")
}
coroutineScope { // Creates a new coroutine scope
launch {
delay(500L)
println("Task from nested launch")
}
delay(100L)
println("Task from coroutine scope") // This line will be printed before nested launch
}
println("Coroutine scope is over") // This line is not printed until nested launch completes
}
enleur
10/12/2018, 10:31 AMmarcinmoskala
10/12/2018, 10:36 AMVsevolod Tolstopyatov [JB]
10/12/2018, 12:21 PMhttps://www.youtube.com/watch?v=P7ov_r1JZ1g▾
CoroutineScope
rationale and kotlinx.coroutines
API overview in 30 minutes.lukaswelte
10/12/2018, 1:13 PMCoroutineScope
which is onError
? So in case any of the coroutines in the scope are cancelled or failing it will not cancel the parent scope routines, but instead invoke the error handler. Or is try-catch
around the coroutineScope {}
currently the only way?muralimohan962
10/12/2018, 2:21 PMlukaswelte
10/12/2018, 3:16 PMimport kotlinx.coroutines.*
fun main() = runBlocking {
repeat(100_000) { // launch a lot of coroutines
launch {
delay(1000L)
print(".")
}
}
}
spierce7
10/12/2018, 3:47 PMRendezvousChannel
. The RendezvousChannel
seems like a PublishSubject
from RX, but the documentation says something that worries me: An element is transferred from sender to receiver only when send and receive invocations meet in time
So I understand that before I start listening to the Channel
, all events emitted to it won't be received. Is it possible though that if I'm already listening to events on the Channel
that I'll miss any?Ruckus
10/12/2018, 4:54 PMlaunch
(like GlobalScope
) your code will work without yield
.enleur
10/13/2018, 7:46 PMsuspend fun whatever() = coroutineScope{
while(isActive){ ... }
}
Paul Woitaschek
10/13/2018, 7:59 PMTwoClocks
10/13/2018, 9:21 PMAllan Wang
10/14/2018, 12:13 AM(T) -> Unit
vs T.() -> Unit
, which strikes me as a bit odd as anyone can use the original variable and forget about trying to get it from the weak reference. With coroutines, I don’t think weak references are used correct?
Would it stand that so long as we make the coroutine scope agree to our lifecycle, we don’t have to worry about leaking variables beyond what we would normally consider when writing synchronous code? More specifically to Android, is there a general practice for writing suspended functions dealing with Context
in a utility class where context would be passed through as an argument?
Is it fine that we keep a global hashmap of deferred results if the scope cancels the job when appropriate?oshai
10/14/2018, 7:37 AMegorand
10/14/2018, 6:22 PMinterface Source : Closeable {
@Throws(IOException::class)
fun read(sink: Buffer, byteCount: Long): Long
}
I’m declaring SuspendingSource
like this:
interface SuspendingSource : Source {
@Throws(IOException::class)
override suspend fun read(sink: Buffer, byteCount: Long): Long
}
which doesn’t compile because of Conflicting overloads
. Is it forbidden to override non-suspend functions with suspend ones?egorand
10/14/2018, 6:22 PMinterface Source : Closeable {
@Throws(IOException::class)
fun read(sink: Buffer, byteCount: Long): Long
}
I’m declaring SuspendingSource
like this:
interface SuspendingSource : Source {
@Throws(IOException::class)
override suspend fun read(sink: Buffer, byteCount: Long): Long
}
which doesn’t compile because of Conflicting overloads
. Is it forbidden to override non-suspend functions with suspend ones?Dominaezzz
10/14/2018, 6:43 PMSource.read
doesn't not know to suspend.egorand
10/14/2018, 6:47 PMBurkhard
10/14/2018, 11:42 PM