marcinmoskala
11/17/2017, 7:35 AMDave Leeds
11/18/2017, 3:32 AMsuspend val
(say, with get() {}
or a delegate) at this point? I tried a few things and nothing worked, but I also wasn't sure if I was just doing it wrong. 🙂Sorin
11/19/2017, 1:45 PMcompile 'org.jetbrains.kotlinx:kotlinx-coroutines-android:0.19.3'
however there is some rightful so skepticism from some of my colleagues.
I would like to know if it is safe to use coroutines in production. I need a professional statement fro my colleagues.
I mostly use suspend
keyword and launch()
marcinmoskala
11/20/2017, 8:06 AMkirillrakhman
11/20/2017, 8:52 AMmain
function suspend
?satejs
11/20/2017, 9:46 AMgildor
11/20/2017, 10:43 AMasync()
is function (coroutine builder) and await
is a function in interface Deferred (returned from async()) and both of them are part of kotlinx.coroutines library, not a part of language or stdlibrary.
You can write own implementations that doesn’t coupled with particular Promise/Feature implementation like in languages where async/await is part of the languagemarcinmoskala
11/20/2017, 10:50 AMelizarov
11/20/2017, 12:40 PMgildor
11/22/2017, 6:16 AMdave08
11/22/2017, 2:34 PMrunBlocking
and join
all jobs with delay
after, have refreshList
as mocked interface, and check if being called expected x times for delay?jimn
11/23/2017, 5:22 AMjimn
11/23/2017, 5:41 AMmatej
11/24/2017, 3:48 PMThe feature "coroutines" is experimental
something new? I didn't notice it until today, and now all my run
and launch
invocations are highlightedjmfayard
11/26/2017, 12:07 PMdekans
11/26/2017, 1:11 PMdave08
11/28/2017, 8:41 AMchristophsturm
11/28/2017, 8:51 AMfstn
11/28/2017, 9:01 AMchristophsturm
11/28/2017, 3:58 PMcy
11/29/2017, 10:02 AMelizarov
11/29/2017, 10:20 AMjoin
if you rely on parent/child rels to split one large task into parallel subtasks. So, to do mySuspendingTask
100 times in parallel you can just do:
fun main(args: Array<String>) = runBlocking {
(0..100).forEach { launch(coroutineContext) { mySuspendingTask() } }
}
Now you are explicit about parallelism — you’ll launched concurrent subtask. No worries, since they are very cheap. You can run millions. You outer job (in this case — main) automatically waits for all the children to complete.elizarov
11/29/2017, 10:22 AM.map { it.await() }
seems to be a common pattern. We might want to introduce extension like .awaitAll()
for it.Paul Woitaschek
11/29/2017, 10:49 AMelizarov
11/29/2017, 10:55 AMval reqs: List<Request> = ... // list of original requests
val chan = Channel<Request>()
launch { for (req in reqs) chan.send(req) } // send all reqs to chan
repeat(n) { // craete a pool of limited number workers
launch { for (req in chan) processRequest(req) }
}
voddan
11/29/2017, 11:11 AMfun main(args: Array<String>) = runBlocking {
(0..100).forEach {
launch(coroutineContext) { // <- limit the number of concurrent threads ?
mySuspendingTask()
}
}
}
elizarov
11/29/2017, 1:42 PMlouiscad
11/30/2017, 9:39 AMonPermissionsRequestResult
, which has been a real pain for Android developers, given the count of permissions helper librariesgregd
11/30/2017, 11:30 PMsuspend
doesn’t work with typealias
?
Example:
typealias MyType = (Any) -> Any
fun testFunction(block: suspend MyType) {}
// ^^^^^^^
// Modifier 'suspend' is not applicable to 'non-functional type'
arocnies
12/01/2017, 4:31 AMrunBlocking {...}
for Kotlin/JS? launch {...}
is relatively straight forward but I just can't seem to figure out how to properly block for a coroutine in JS.arocnies
12/01/2017, 4:31 AMrunBlocking {...}
for Kotlin/JS? launch {...}
is relatively straight forward but I just can't seem to figure out how to properly block for a coroutine in JS.gildor
12/01/2017, 5:17 AMpdvrieze
12/01/2017, 10:05 AMrunBlocking
doesn't do what you may think it does. It runs everything (except subcoroutines) on the same thread (the one that started it). In some ways this fits well with Javascript.
You cannot actually wait for a coroutine completion in Javascript. What you do is use a callback on completion. Waiting for a coroutine amounts to either inside the coroutine just doing what you want with the result or starting a new coroutine that invokes await on the previous one.gildor
12/01/2017, 10:26 AM