Hey, hope this isn't too annoying!
# announcements
a
Hey, hope this isn't too annoying!
m
Not too sure, but maybe something like this:
z
Try not to use
GlobalScope
if at all possible. Usually there is some concept of “lifetime” that surrounds where you’re launching coroutines from, so you can create a
CoroutineScope
that represents that. Other than that, Mon’s solution is probably what I’d do.
And come join us in #C1CFAFJSK!
a
Thanks both! What I have done for now is
Copy code
val responses = needsResponses.map {
        GlobalScope.async {
            // get response
        }
    }

    responses.map { it.await() }.map {
        // process response
    }
Will look into creating a coroutine scope. Any particular disadvantages of using GlobalScope? There's no chance of this workflow overlapping with another instance of it
Actually, rewrote to something more similar to Mon's solution, thanks!
Copy code
needsResponses
        .map {
            GlobalScope.async {
                // get responses
            }
        }
        .awaitAll()
        .forEach {
            // process responses
        }
z
GlobalScope
lets you leak coroutines. It also makes it easier to refactor code without it being in the correct scope in its new location.
k
How do u like Kotlin so far compared to Golang @Ani Mehta