cats-effect icon indicating copy to clipboard operation
cats-effect copied to clipboard

Add a `memoizedAcquire` method to `Resource`

Open Daenyth opened this issue 2 years ago • 5 comments

Ref #3513

I'm not sure how to unit test this exactly, I'm open to guidance or commits for that

Daenyth avatar Nov 08 '23 15:11 Daenyth

To test this I would write to Refs in your acquire and use, and assert on the state of those refs to check that it's behaving as you expect. I wouldnt worry about concurrent testing since memoize is pulling most of the weight

SystemFw avatar Nov 14 '23 20:11 SystemFw

I don't think we need to add any new tests specifically because of this PR, unless there are existing gaps in the existing memoize tests.

To be clear, what I'm proposing is that we refactor so it looks like this:

def memoizedAcquire(ra: Resource[F, A]): Resource[F, F[A]] =
  /* move existing memoize implementation here */

def memoize(ra: Resource[F, A]): Resource[F, Resource[F, A]] = 
  memoizedAcquire.map(Resource.eval(_))

Then all the existing memoize tests can just be in terms of memoizedAcquire.

armanbilge avatar Nov 14 '23 20:11 armanbilge

Yeah fair enough, with that refactor I would agree that we don't need any new tests

SystemFw avatar Nov 14 '23 20:11 SystemFw

I'm a huge fan of not having to add new tests. I will get to that refactor when/as I have time but if anyone wants to beat me to it, the branch is open for maintainer commits ;)

Daenyth avatar Nov 14 '23 21:11 Daenyth

I don't have the time to update this branch with the changes but I encourage anyone motivated to take over

Daenyth avatar Jul 01 '24 15:07 Daenyth

Hi @Daenyth, I would be interested in taking this over if that's ok. I'd love to see this feature land in the 3.6 release :-)

satabin avatar Jul 12 '24 12:07 satabin

@satabin Go for it! I think you'll need to pull this branch locally and open a new pull request so you can push to it. Please be sure to refrain from rebasing the commits; we can carry the conversation more easily from this PR to that one if the shas are not rewritten.

djspiewak avatar Jul 13 '24 19:07 djspiewak

I opened #4105 to continue the work on this PR.

satabin avatar Jul 18 '24 13:07 satabin