https://kotlinlang.org logo
#coroutines
Title
# coroutines
k

kevinherron

10/30/2018, 11:37 PM
is there a way to configure the thread names used by the underlying pools and executors for the coroutine dispatchers provided by stdlib?
g

groostav

10/31/2018, 12:38 AM
you could of course make your own
ExecutorService
and then call the extension function
asCoroutineDispatcher()
, that would get you running on threads named whatever you wanted
alternatively you can use CoroutineContext elements
CoroutineName
eg:
Copy code
suspend fun doWork(workItem: WorkItem){
  withContext(CoroutineName("My-API-$workItem") + IOPool){
    //do IO work that your lib offers, or similar
  }
}
k

kevinherron

10/31/2018, 1:11 AM
i'm currently using my own dispatcher from an ExecutorService, but I was looking for a way to use the built in ones now
they seem to be better than just an ExecutorService in some cases
especially the FJP-based default and the IO dispatcher
2 Views