withMainDispatcher

suspend fun withMainDispatcher(dispatcher: CoroutineDispatcher? = null, action: suspend () -> Unit)(source)

Runs action with dispatcher set up as the main dispatcher, which will be reset afterward.

If dispatcher is null, a single-threaded dispatcher is used.

See Dispatchers.setMain for details. This function, if used exclusively, ensures that only one main dispatcher is active at any point in time.