<@U0RM4EPC7> it seems like the new `resource { }` ...
# arrow
p
@simon.vergauwen it seems like the new
resource { }
DSL releases resources in the wrong order - see 🧵
Copy code
import arrow.fx.coroutines.Resource
import arrow.fx.coroutines.release
import arrow.fx.coroutines.resource

internal infix fun <A, B> Resource<A>.flatTap(resource: (A) -> Resource<B>): Resource<A> =
    flatMap { a -> resource(a).map { a } }

suspend fun main() {
    fun str(string: String) = resource { string.also { println("acquire($it)") } } release { println("release($it)") }
    suspend fun <A> Resource<A>.use() = use { println("use($it)") }

    println("-- flatMap --")
    str("outer")
        .flatMap { str("inner") }
        .use { println("use($it)") }

    println("-- flatTap --")
    str("outer")
        .flatTap { str("inner") }
        .use { println("use($it)") }

    println("-- zip --")
    str("outer").zip(str("inner")).use()
}
in 1.0.1 produces
Copy code
-- flatMap --
acquire(outer)
acquire(inner)
use(inner)
release(inner)
release(outer)
-- flatTap --
acquire(outer)
acquire(inner)
use(outer)
release(inner)
release(outer)
-- zip --
acquire(outer)
acquire(inner)
use((outer, inner))
release(inner)
release(outer)
however 1.1.2 produces (same code, same imports)
Copy code
-- flatMap --
acquire(outer)
acquire(inner)
use(inner)
release(outer)
release(inner)
-- flatTap --
acquire(outer)
acquire(inner)
use(outer)
release(outer)
release(inner)
-- zip --
acquire(outer)
acquire(inner)
use((outer, inner))
release(outer)
release(inner)
and I’ve found the cause. Not sure about contributing process but (current master)
arrow/fx/coroutines/Resource.kt:727
should be
finalizers.update(finalizer::prependTo)
test case
Copy code
"flatMap resource is released first" {
      checkAll(Arb.positiveInt(), Arb.negativeInt()) { a, b ->
        val l = mutableListOf<Int>()
        fun r(n: Int) = Resource({ n.also(l::add) }, { it, _ -> l.add(-it) })

        r(a).flatMap { r(it + b) }
          .use { it + 1 } shouldBe (a + b) + 1

        l.shouldContainExactly(a, a + b, - a - b, -a)
      }
    }
would cover it. I’m happy to look into wrapping this up into a PR later this evening - but don’t feel the need to wait for it if you want to fix it yourself or in your own way 😉
s
Hey @phldavies, You're absolutely right! Insane a test for this was missing 😕 When I rewrote the implementation, I made the assumption the Resource tests covered this. Thanks for the great catch, and for making a PR!! 😍 Ran the CI on your PR, and approved it!
p
Awesome, thanks @simon.vergauwen for the quick review - happy to help. Hopefully this is in time to make
1.1.3
the next announced release as it would be great to be able to switch. At the moment, 1.1.2 breaks some expectations we have around resource releasing.
s
Yes, I am going to try and get this in 1.1.3 hopefully next week together with the official announcements.
👍 1
p
Is there anything left to do to get this merged in?
s
I asked in the internal release channel. We're a bit in a bind, because 1.1.0 and 1.1.2 got released by accident through Github Actions :s
So merging this means we need to skip to
1.1.3
😭
p
On the plus side, it might give you a chance to check the release process won’t automatically publish to maven central this time, and that the Gradle MPP publish works too?
s
Yes, the Gradle MPP publish has been fixed. It was actually really strange what happened, 2 separate running Github Actions interfered with each other, and an
alpha
pipeline published a
stable
pipeline result 😕 This was due to how long the tasks take to run in Github actions, and we're currently fixing the issues to it cannot happen again.
p
Is it something the concurrency flag in Github Actions can help with?
s
Thanks for the tip, going to share that!
p
Any updates on when a 1.1.3 might be released? We’d quite like to starting playing with
effect { }
but this
resource { }
bug is a blocker for us 🙂
s
Hey @phldavies, I was out last week sick from Covid 😕 I'm trying to close all open PRS with some Arrow maintainers, and then we're going to release 1.1.3 immediately
Hopefully next week
p
Sorry to hear you were ill - hope you weren’t hit too badly with Covid (I’ve so far managed to avoid it somehow). Let me know if there’s anything I can assist with.
s
Thank you, it was quite mild but still sucked to be out 😅 Will do @phldavies. I'll keep you posted if I have any news 😉
👌 1
@phldavies your fix will be available later today in 1.1.3-alpha.4 in case you'd want to pin it to that alpha version
🙌 1
p
Looks to be built but not in maven central? Does it need to be manually propagated from sonatype staging, or is it only available from there?
s
Sometimes it needs some time to sync to maven central and seems to be getting worse lately. Github Action ran normally so it should show up soon
p
Looks like it’s there as
1.1.3-alpha.4.0+2022-05-17T09-11-10-723810Z
, is that intentional?