Skip to content

Add a memoizedAcquire method to Resource#4105

Merged
djspiewak merged 11 commits into
typelevel:series/3.xfrom
satabin:gb-lazy-resource
Dec 8, 2024
Merged

Add a memoizedAcquire method to Resource#4105
djspiewak merged 11 commits into
typelevel:series/3.xfrom
satabin:gb-lazy-resource

Conversation

@satabin

@satabin satabin commented Jul 18, 2024

Copy link
Copy Markdown
Contributor

As mentioned in #3890 (comment), this is the PR taking over #3890 to add a specialized version of memoized for Resource.

Ref #3513

Comment thread kernel/shared/src/main/scala/cats/effect/kernel/Resource.scala
@djspiewak djspiewak changed the title [Taking Over] Add a memoizedAcquire method to Resource Add a memoizedAcquire method to Resource Jul 18, 2024
@satabin

satabin commented Sep 17, 2024

Copy link
Copy Markdown
Contributor Author

I did not forget about this PR. Testing it is currently blocked by the PureConc finalizer problem (see #3430). As soon as there is a fix, I will design a test using it.

@armanbilge armanbilge added this to the v3.6.0 milestone Nov 21, 2024
@armanbilge armanbilge closed this Nov 21, 2024
@armanbilge armanbilge reopened this Nov 21, 2024
@djspiewak

Copy link
Copy Markdown
Member

Sadly I think this one might be really blocked on the PureConc stuff. It's hard to be totally comfortable with this absent tests.

@armanbilge

Copy link
Copy Markdown
Member

To refresh my memory: the reason we couldn't write the test in IO (using the test runtime) is because I think that IO actually doesn't reproduce this bug thanks to the optimization introduced in #1742. Basically, the map is able to execute immediately without requiring an additional iteration of the runloop and thus skips the cancelation check.

@armanbilge

Copy link
Copy Markdown
Member

It's hard to be totally comfortable with this absent tests.

Also point of clarification, there are several tests for memoizedAcquire (which is just a refactoring of memoize). During refactoring I introduced a bug, which Daniel U caught in review, and this test is intended to catch that.

@satabin

satabin commented Nov 25, 2024

Copy link
Copy Markdown
Contributor Author

It's hard to be totally comfortable with this absent tests.

Also point of clarification, there are several tests for memoizedAcquire (which is just a refactoring of memoize). During refactoring I introduced a bug, which Daniel U caught in review, and this test is intended to catch that.

Yes, the currently committed test does not reflect this, it is still an attempt I wrote before noticing I couldn't reproduce it with IO. I will update the test with what I think should work, once the PureConc behavior is fixed.

djspiewak
djspiewak previously approved these changes Nov 26, 2024

@djspiewak djspiewak left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alright, let's go for it.

@djspiewak

Copy link
Copy Markdown
Member

Needs prePR

@satabin

satabin commented Nov 27, 2024

Copy link
Copy Markdown
Contributor Author

Needs prePR

Yes, I should have time to work on this this weekend.
Regarding the test I wanted to add to check that acquisition cancellation does not occur after the resource has been actually acquired and before it is put in the release list. Should I just not add it, or add and ignore it, until PureConc is fixed? What do you think is the best approach?

@djspiewak

Copy link
Copy Markdown
Member

Regarding the test I wanted to add to check that acquisition cancellation does not occur after the resource has been actually acquired and before it is put in the release list. Should I just not add it, or add and ignore it, until PureConc is fixed? What do you think is the best approach?

Ideally add it and then mark pendingUntilFixed.

Comment on lines +1174 to +1175
// TODO enable once `PureConc` finalizer bug is fixed. Test is indefinitely waiting for finalizers as of now
/*

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of commenting the test you can use pendingUntilFixed :)

"round trip through js.Promise" in ticked { implicit ticker =>
forAll { (ioa: IO[Int]) =>
ioa.eqv(IO.fromPromise(IO(ioa.unsafeToPromise())))
}.pendingUntilFixed // "callback scheduling gets in the way here since Promise doesn't use TestContext"

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

True, I made a mistake in my test design. It should be ok now. See cd61033

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@armanbilge I took your comment into account and added a pending test. Do you think this PR is ready to be merged now?

@djspiewak
djspiewak merged commit 0bde608 into typelevel:series/3.x Dec 8, 2024
@satabin
satabin deleted the gb-lazy-resource branch December 9, 2024 06:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants