Kotlin equivalent of AsyncTask.SERIAL_EXECUTOR?

AsyncTask is dead (deprecated)

So what structure do I use to replace my AsyncTask.SerialExecutor? I’ve made the dive into coroutines and channels, but there’s nothing I’ve come across that can serially queue a series of requests and ensure they execute in turn with no concurrency. Nothing that isn’t a) already deprecated (like actor) or b) experimental (not something I want to touch with a production build).

Maybe I’m missing something in how CoroutineScope is defined? Some little trick with channels?

I’ve also asked this question on stackoverflow and it has received an answer. But I believe this solution has some limitations. I’m wondering if there is a ‘proper’ solution.

What you are asking for (sequential execution) is the basic behavior of coroutine code of you don’t launch or async.

If you want to queue up tasks, just send them through a Channel (which is a just a queue with suspend method) and read from it in a for-loop.

Docs: “Conceptually, a channel is similar to BlockingQueue, but it has suspending operations instead of blocking ones and it can be closed.”

Your use case is described here in the Fan In pattern.