pniederw
02/09/2017, 3:44 AMdefer
to async
, will you also rename future
back to async
?elizarov
02/09/2017, 5:54 AMasync
and future
return different future classes. async
result type is Deferred
, while future
result type is CompletableFuture
. They cannot both have the same name. Which one to call async
then? The one that returns Deferred
, of course, because it works anywhere (including any Android version), while CompletableFuture
is only available on JDK8 and latest Androids.pniederw
02/09/2017, 5:55 AMelizarov
02/09/2017, 5:59 AMasync
(different libs might want to use different futures), but we'd rather nudge people into using this particular implementation of futures, since it does not have any blocking operations (better for coroutines -- less error-prone), has clear exception-transparency semantics, supports laziness, and will work with upcoming select
pniederw
02/09/2017, 6:05 AMCompletableFuture
. that’s my perspective on this topic.elizarov
02/09/2017, 6:19 AMasync
.pniederw
02/09/2017, 6:33 AMsuspend fun <S, T> Iterable<S>.runConcurrently(action: suspend S.() -> T): Collection<T>
async
elizarov
02/09/2017, 6:34 AMkotlinx.coroutines
, toopniederw
02/09/2017, 6:35 AMsuspend fun <S, T> (suspend () -> S).runConcurrentlyWith(action: suspend () -> T): Pair<S, T>
suspendingFunction { … }.runConcurrentlyWith { … }
suspendingFunction
to make the type system understand that the lambda is a suspending lambda.suspend fun <T> suspendingFunction(f: suspend () -> T): suspend () -> T = f
elizarov
02/09/2017, 6:45 AMcoroutine { one() } pairWith coroutine { two() } // result is Pair<A,B>
or
collection.map { coroutine { process(it) } }.all() // result is `List<T>`
pniederw
02/09/2017, 6:53 AMfun Iterable<CompletableFuture>.await()
.elizarov
02/09/2017, 7:21 AM