unless I have to do this: ``` return templates.ma...
# coroutines
m
unless I have to do this:
Copy code
return templates.map { renderTemplatePath -> 
  runBlocking {
    val result = async {
      renderMetricTimer.tagVal(package).time {
        //code
      }
    }
    result.await()
 }.toSet()
}
Obviously, I am new to coroutines, but this seems like a lot of coroutine builders, no?
s
Why do you run something in async if you await it immediately after?
m
the
timer
function is a
suspend
function.
Copy code
suspend fun <T> NeedsTag1<BooleanTagValue, Timer>.time(toTime: suspend () -> T): T {
    val timerStarted = this.start()
    try {
        val result = toTime()
        timerStarted.tagVal(true).stop()
        return result
    } catch (e: Throwable) {
        timerStarted.tagVal(false).stop()
        throw e
    }
}`
s
You can call suspend functions from inside runBlocking
m
OH, and avoid the
async
??
s
Yes. Async is for parallel work only
👍 1
m
I'm still confuse on those. I thought that would use
async
when I need to return something.
n
Nah, you can just do:
Copy code
runBlocking {
    renderMetricTimer.tagVal(package).time {
        //code
    }
}.toSet()
👍 1