Provide @ShellMainThread dispatcher as MainCoroutineDispatcher
Changes the CoroutineDispatcher (and thus scope) for shell.main to a MainCoroutineDispatcher backed by a Handler. This is because Executor#asCoroutineDispatcher assumes the #execute will post the runnable but ShellExecutor actually runs it immediately if already on the same thread. Using Handler#asCoroutinesDispatcher doesn't have the same problem because the backing Handler always uses #post to run the Runnable. CoroutineDispatchers already have this immediate vs posted functionality built-in (see CoroutineDispatcher#isDispatchNeeded), and MainCoroutineDispatcher#immediate is available to callers that want to explicitly run coroutines in an immediate (non-dispatching) way. Bug: None Flag: EXEMPT bugfix Test: m Change-Id: I516351b93d103b59f8fa8d191f300122acdf9001
Loading
Please register or sign in to comment