Some library I use requires an ExecutorService to ...
# coroutines
m
Some library I use requires an ExecutorService to run on (not just an Executor). The ExecutorService runs for the whole application lifetime, so would only be shut down if the whole application shuts down. Am I crazy for doing this (its basically the same as Dispatchers.IO.asExecutor() and all the lifecycle stuff is basically not implemented, because as I said the whole thing basically does not shut down)?
Copy code
private val ioDispatcherExecutorService by lazy {
    object : AbstractExecutorService() {
        private val dispatcher = <http://Dispatchers.IO|Dispatchers.IO>
        override fun execute(command: java.lang.Runnable) {
            dispatcher.dispatch(EmptyCoroutineContext, command)
        }

        override fun shutdown() {}

        override fun shutdownNow(): MutableList<java.lang.Runnable> {
            return mutableListOf()
        }

        override fun isShutdown(): Boolean {
            return !dispatcher.isActive
        }

        override fun isTerminated(): Boolean {
            return !dispatcher.isActive
        }

        override fun awaitTermination(timeout: Long, unit: TimeUnit): Boolean {
            return true
        }
    }
}
m
I have a feeling that extending AbstractExecutorService and delegating
execute
to the Executor created by
asExecutor
would more likely be a valid service. But my experience is limited.