dave08
11/28/2017, 9:29 AMPaul Woitaschek
11/29/2017, 9:42 AMPaul Woitaschek
11/29/2017, 9:43 AMPaul Woitaschek
11/29/2017, 9:44 AMdiesieben07
11/29/2017, 9:46 AMuser
11/29/2017, 9:55 AM(0..100).chunked(3).map { tasks ->
tasks.map {
async { mySuspendingTask() }
}.map { defered ->
job.await()
}
}
Paul Woitaschek
11/29/2017, 9:55 AMuser
11/29/2017, 9:56 AMlaunch
and job.join()
if you don’t need resultPaul Woitaschek
11/29/2017, 9:56 AMgildor
11/29/2017, 9:56 AMgildor
11/29/2017, 9:56 AMgildor
11/29/2017, 9:58 AMval context = newFixedThreadPoolContext(nThreads = 3, name = "myThreadPool")
(0..100).map {
async(context) { mySuspendingTask() }
}.map {
it.join()
}
gildor
11/29/2017, 9:59 AMPaul Woitaschek
11/29/2017, 10:00 AMPaul Woitaschek
11/29/2017, 10:03 AMPaul Woitaschek
11/29/2017, 10:03 AMelizarov
11/29/2017, 10:08 AMelizarov
11/29/2017, 10:22 AMasync
and map
over the results again to retrieve them:
(0..100).map { async { mySuspendingTask() } }.map { it.await() }
Paul Woitaschek
11/29/2017, 10:48 AMNo worries, since they are very cheap. You can run millions.
gildor
11/29/2017, 10:52 AMelizarov
11/29/2017, 10:53 AMpdvrieze
11/29/2017, 3:25 PMkenkyee
11/29/2017, 5:32 PMpdvrieze
11/29/2017, 7:56 PMpdvrieze
11/29/2017, 8:03 PMstartActivtiyForResult
is called on this fragment - fragments will receive the events and are automatically saved with their arguments (the continuation is provided as such an argument with a Parcelable wrapper). There are various ways to break it - Don't capture View objects as I haven't special cased them - activities are sufficient.kenkyee
11/29/2017, 8:43 PMpdvrieze
11/29/2017, 10:56 PMonActivityResult
is called. I'm using Kryo with various custom mappings to actually serialize (and harder) deserialize the continuation object. Like I say, the serialization does various things. It special cases the marker objects used by Kotlin in for example SafeContinuation. It also handles Kotlin objects special (refer to the value of INSTANCE, don't load another one). It also rips out all Context objects and on reserialization sets them based on the passed in activity (it could be more robust storing the actual type and verifying on deserialization). If you want to see how it works, the serialization is defined in https://github.com/pdvrieze/darwinlib/blob/master/src/main/java/nl/adaptivity/android/kryo/KryoIO.ktelizarov
11/30/2017, 7:11 AMUNDEFINED
and RESUME
) into instance internal enums and make various xxxContinuation classes implement Serializable
. This will not make the whole serialization story entirely trivial, though, because you’ll still have to carefully rip out and reinstall contexts when serializing/deserializing coroutines.gildor
11/30/2017, 8:13 AMonActivityResult
with coroutines would be a huge thing!