thread pool • delay suspends coroutine (suspend function) • when coroutine is waiting, the thread is returned to thread pool and resumes later with free thread in the pool • runBlocking runs new coroutine and blocks current thread
{ n } } val sum = deferred.sumBy { it.await() } • async is like launch but returns Deferred<T>. • Deferred<T> has await() • await() returns T, result of the coroutine
the computation finishes. • Coroutines can suspend only in coroutine or suspend function Error: Suspend functions are only allowed to be called from a coroutine or another suspend function
returns n } Error: Suspend functions are only allowed to be called from a coroutine or another suspend function • Add suspend modifier to function to fix this and call from a coroutine or another suspend function suspend fun workload(n: Int): Int { ... }