Sergey Chikin
02/19/2018, 9:20 AMasync
coroutine builder, in other words in your code instead of calling asyncResult {lambda}
you can do simply async {lambda}
and not even build this function. You can specify where the coroutine will be executed by passing CoroutineContext
to async
like this: async(routineContext) { lambda }
, where I have routineContext
defined as follows:
internal val routineContext: CoroutineContext by lazy {
log.debug("Initializing pool with configuration $configuration")
when (configuration) {
is SingleThreadConfiguration -> newSingleThreadContext(configuration.name)
is FixedThreadPoolConfiguration -> newFixedThreadPoolContext(configuration.threads, configuration.name)
is CachedThreadPoolConfiguration -> CachedCoroutineDispatcher(configuration.name)
is ForkJoinPoolConfiguration -> ForkJoinCoroutineDispatcher(configuration.name, configuration.parallelism)
else -> throw ConfigurationException("Unknown thread pool requested")
}
}