Closed i-walker closed 2 years ago
The goal of this PR is to introduce similar functionality to autoClose
but for Arrow Fx Coroutines Resource.
In an ideal world the API would be the folllowing:
class XXXSpec : StringSpec({
val a by resource(resourceA) // A & B *have to be independent*
val b by resource(resourceB)
"test {
// usage
}
}
If there is no relationship between A
& B
they can lazily be initialised by beforeSpec
which has support for suspension. Which can then be safely used inside the test.
if A
& B
do depend on each-other the user should do:
class XXXSpec : StringSpec({
val (a, b) by resource(resourceA.flatMap { a -> resourceB(a) })
}
The following is incorrect, and requires runBlocking
class XXXSpec : StringSpec({
val a by resource(resourceA)
val b by resource(resourceB(a)) <-- relying on directly on `a` which requires it to be evaluated with `runBlocking`.
}
We can of course try to avoid runBlocking
on a best-effort basis, based on the requirements that are described above.
PS: reason I used by
instead of =
in the snippets above is that is required if you want to make it (best-effort) lazy.
CI is failing, bc kotest.common.runBlocking isn't available in Js
In kotest proper I added a helper function that runs runBlocking on jvm or just inline on js.
@sksamuel I couldn't find the snippet. Could you link it, please? Or just the js
actual fun
would be great.
@i-walker updated in my example project latest Arrow, and avoids runBlocking
as much as possible.
Thanks @nomisRev I will go for your encoding in https://raw.githubusercontent.com/nomisRev/ktor-arrow-example/e498a5bd221f9240002f8adedc20a20e6d9e794e/src/test/kotlin/io/github/nomisrev/resource.kt
Lgtm
Thanks everyone 🙌🏾 I am prepping the release and a release post for 1.3.0 this week and hope to get this out by next week or so
Awesome @i-walker! Let me know if I can help with anything.
Loving this.
On Tue, May 17, 2022, 4:32 AM Imran Malic Settuba @.***> wrote:
Merged #143 https://github.com/kotest/kotest-extensions-arrow/pull/143 into master.
— Reply to this email directly, view it on GitHub https://github.com/kotest/kotest-extensions-arrow/pull/143#event-6622830353, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAFVSGWZEN3N35XLQ224H4TVKNRUJANCNFSM5PN65WOQ . You are receiving this because you were mentioned.Message ID: @.*** com>
inspired by https://github.com/nomisRev/ktor-arrow-example/blob/main/src/test/kotlin/io/github/nomisrev/resource.kt and arrow-fx-coroutines-test