diff options
author | Harsh Shandilya <me@msfjarvis.dev> | 2021-12-09 10:07:54 +0530 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-12-09 04:37:54 +0000 |
commit | 8db0b67ce9ba4a5e56c04c1bea3a738eacb176cf (patch) | |
tree | 46700b7a3da32065e073bffbf22765c7e2f30d32 /coroutine-utils/src/main | |
parent | 933558caf8266677dc26497d7c7b930254f4fb07 (diff) |
Refactor coroutine testing setup (#1583)
* coroutine-utils: init
* coroutine-utils-testing: init
* format-common: switch over to using DispatcherProvider
* Convert Binds method to an extension function
* Add Dispatcher module
Diffstat (limited to 'coroutine-utils/src/main')
-rw-r--r-- | coroutine-utils/src/main/kotlin/dev/msfjarvis/aps/util/coroutines/DispatcherProvider.kt | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/coroutine-utils/src/main/kotlin/dev/msfjarvis/aps/util/coroutines/DispatcherProvider.kt b/coroutine-utils/src/main/kotlin/dev/msfjarvis/aps/util/coroutines/DispatcherProvider.kt new file mode 100644 index 00000000..a7c4530d --- /dev/null +++ b/coroutine-utils/src/main/kotlin/dev/msfjarvis/aps/util/coroutines/DispatcherProvider.kt @@ -0,0 +1,22 @@ +/* + * Copyright © 2014-2021 The Android Password Store Authors. All Rights Reserved. + * SPDX-License-Identifier: GPL-3.0-only + */ + +package dev.msfjarvis.aps.util.coroutines + +import javax.inject.Inject +import kotlinx.coroutines.CoroutineDispatcher +import kotlinx.coroutines.Dispatchers + +/** Interface to allow abstracting individual [CoroutineDispatcher]s out of class dependencies. */ +public interface DispatcherProvider { + + public fun main(): CoroutineDispatcher = Dispatchers.Main + public fun default(): CoroutineDispatcher = Dispatchers.Default + public fun io(): CoroutineDispatcher = Dispatchers.IO + public fun unconfined(): CoroutineDispatcher = Dispatchers.Unconfined +} + +/** Concrete type for [DispatcherProvider] with all the defaults from the class. */ +public class DefaultDispatcherProvider @Inject constructor() : DispatcherProvider |