Compatibility with Arrow • opensavvy.prepared.compat.arrow.coroutines • preparedResource
preparedResource¶
fun <T> preparedResource(block: suspend TestResourceScope.() -> T): PreparedProvider<T>
Declares a prepared value that contains Arrow Resources.
The resources are released at the end of the test.
Example¶
val userProcessor: Resource<UserProcessor> = resource({
UserProcessor().also { it.start() }
}) { p, _ -> p.shutdown() }
val dataSource: Resource<DataSource> = resource({
DataSource().also { it.connect() }
}) { ds, exitCase ->
println("Releasing $ds with exit: $exitCase")
withContext(Dispatchers.IO) { ds.close() }
}
// Note the 'by'!
val service by preparedResource {
Service(dataSource.bind(), userProcessor.bind())
}
test("Some kind of test") {
service().createEntity("…")
}
External resources¶
See also¶
-
TestResourceScopeOverview of Prepared and Arrow's compatibility. -
asPreparedConvert aResourceinto a Prepared value.