Last active
April 18, 2018 16:13
-
-
Save tomkoptel/6563da1e3c7426d36596ed84e354f5d7 to your computer and use it in GitHub Desktop.
Wrapper factory API with a purpose to create a single entry point hook to later delegate Job instances.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import kotlinx.coroutines.experimental.CoroutineScope | |
import kotlinx.coroutines.experimental.CoroutineStart | |
import kotlinx.coroutines.experimental.DefaultDispatcher | |
import kotlinx.coroutines.experimental.Job | |
import kotlin.coroutines.experimental.CoroutineContext | |
import kotlinx.coroutines.experimental.launch as coroutineLaunch | |
/** | |
* Acts as dependency provider. Later used in the test env to provide suspendable UI tests. | |
*/ | |
interface CoroutinesProvider { | |
fun launch( | |
context: CoroutineContext = DefaultDispatcher, | |
start: CoroutineStart = CoroutineStart.DEFAULT, | |
parent: Job? = null, | |
block: suspend CoroutineScope.() -> Unit | |
): Job | |
companion object { | |
fun default(): CoroutinesProvider = object : CoroutinesProvider { | |
override fun launch( | |
context: CoroutineContext, | |
start: CoroutineStart, | |
parent: Job?, | |
block: suspend CoroutineScope.() -> Unit | |
): Job { | |
// It is an alias to the `kotlinx.coroutines.experimental.launch` | |
return coroutineLaunch(context, start, parent, block) | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment