Repository navigation
1.5.0: Closeable pulls, readHandle, foldLeft and toGenerator - #11
Merged
Merged
Conversation
…e output and hand it to a generator
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Builds on #10 (1.4.2); merge that first and this diff reduces to the 1.5.0 commit.
Added
Closeable: a pull that holds a handle is closed exactly once by the compile loop, when the stream ends, whentakeortakeWhilehalts it early, or when an effect throws.Read,HttpRequest,ResourcePull,ResourceObjectPull,ResourcePullConcatandPDOPullimplement it;PDOPull::close()callscloseCursor(), which frees a MySQL connection after an unbuffered result set is cut short. Afterclose()a source yields EOF.Functions\io\readHandle(IO $open, int $chunk = 65536): Stream, a thin front over the newOpenedReadresource: theIOruns on the first pull, the handle is closed at EOF and throughCloseable. AnIOthat does not open a stream resource is refused.foldLeft($initial)($f)on a stream, partially applied likeImmList, returningIO<B>;compile()->fold($initial, $f)on the compiler. The fold runs on the lazy loop, one element at a time.compile()->toGenerator(): aGeneratorfor consumers outside the IO discipline. Effects run as the consumer iterates, and the source is closed when the generator finishes or is abandoned.finallythat closes;drain,toList,toArray,foldandtoGeneratorall iterate it.Behaviour change, for the release note
Readcloses its file handle at end of stream instead of when the last reference goes away. The only observable difference is when the descriptor is released; a pull after close yields EOF, as a second read did before.Compilablegainedfold()andtoGenerator(), so a customPulloutside the family that does not use the sharedCompileOpshas to add them.Specs
CloseableSpec,ReadHandleSpec,FoldSpec,ToGeneratorSpec; 190 tests.