question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Introduce awaitAll and joinAll extensions for collections for Deferreds/Jobs

See original GitHub issue

joinAll is simple map { it.join() }, while awaitAll needs a slightly more involved implementation than a simple map { it.await() }. It shall actually wait on all of the deferreds from collection and crash as soon as any one of them crashes.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:11
  • Comments:10 (6 by maintainers)

github_iconTop GitHub Comments

8reactions
fvascocommented, Nov 29, 2017

joinAll is simple map { it.join() }

onEach should be considered to avoid collection’s copy.

3reactions
elizarovcommented, Apr 6, 2018

@raulraja We try to keep kotlinx.coroutines idiomatic with respect to Kotlin stdlib. We don’t plan to have any multiple-arity overloads. Idiomatic way to write your code is:

data class Joined<A, B, C>(a: A, b: B, c: C)

val op1: Deferred<A> = async { ... }
val op2: Deferred<B> = async { ... }
val op3: Deferred<C> = async { ... }

val results = Joined(op1.await(), op2.await(), op3.await())
Read more comments on GitHub >

github_iconTop Results From Across the Web

Awaiting Multiple Coroutines the Clean Way | by Matt Robertson
When we launch a coroutine in Kotlin using launch we are returned the resulting Job. We can wait for the coroutine to finish...
Read more >
awaitAll - Kotlin
Awaits for completion of given deferred values without blocking a thread and resumes normally with the list of values when all deferred computations...
Read more >
Kotlin Coroutines - How to block to await/join all jobs?
I want all calls to launch concurrently, and block until all calls are done/the response is acted on, and then return a new...
Read more >
Java源代码 - 摸瓜
AwaitKt$awaitAll$2.java; AwaitKt$joinAll$1.java; TimeoutCancellationException.java; CoroutinesInternalError.java; bm.java; b.java; ci.java; bi.java; w.java ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found