Short requirement: have ability to create corotine context, which will executed in the single thread only (e.g. without parallelism).
Additional requirement: it is better to use existing CommonPool (e.g. Thread Pool) for these tasks
Actually kotlin coroutines have method newSingleThreadContext
which will create separate thread and schedule all tasks into it. However, this is dedicated thread, so ~1000 such contexts will require a lot of resources.
Therefore, I'd like to have context with the following characteristics:
- Maximum one task can be executed at the same time
- This context should reuse any other (e.g. parent context). E.g context should hold no additional threads