-
Notifications
You must be signed in to change notification settings - Fork 621
Removed Stream.bracketCancellable and Pull.acquire* #1603
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Removed Stream.bracketCancellable and Pull.acquire* #1603
Conversation
…res in fs2-io, moved FileHandle creation to Resource and in FileHandle companion
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm satisfied by the argument behind this PR, and the removal of several complex bits is quite nice. Left one minor comment on Pull.singleton
| * Takes the first value output by this stream and returns it in the result of a pull. | ||
| * If no value is output before the stream terminates, the pull is failed with a `NoSuchElementException`. | ||
| * If more than 1 value is output, everything beyond the first is ignored. | ||
| */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder if there is any particular reason for the inconsistency with compile.lastOrError
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's the inconsistency, just the name? I'll rename to headOrError.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just the last vs first behaviour. I can see how Pull is more first-y (uncons), but it's inconsistent with lastOrError. Not a big deal though
Stream.bracketCancellableandStream.bracketCaseCancellableallowed early, manual finalization of resources. Upon invoking the finalizer, the internal resource would be cleaned up, ensuring we don't leak references to already invoked finalizers. Now that we introduce a scope for eachbracket, folks would expect that invoking cancelation of this case also closes the dedicated scope -- i.e., we don't leak scopes either. Instead of implementing this, I'd like to remove these operations instead. There were no tests for these operations and they were very rarely used. Searching GitHub shows no GH hosted open source projects use either operation.Similarly,
Pull.acquireCancellableprovided a mechanism to manually invoke finalizers. I added this back in #662 to fix resource leaks, but the motivating use cases at the time are all addressed now by using effect level bracketing.Removal of
Pull.acquireis perhaps the most controversial. WhenPullwas the primary mechanism in which scopes were created, acquiring a resource viaPullmade more sense than it does now.This PR also introduces a
s.pull.headOrErrormethod, that converts aStream[F, O]to aPull[F, INothing, O]. Uses ofPull.acquirecan be replaced withStream.bracket(acquire)(release).pull.headOrError.Note: the only place where
Pull.Cancellablewas used was in the constructors forFileHandleinfs2.io.file.pulls. These were vestiges of a time beforecats.effect.Resource. These constructors were removed in favor of new constructors onFileHandlecompanion that returnResource[F, FileHandle[F]].