-
Couldn't load subscription status.
- Fork 1.4k
Port ZStream.fromInputStream (the one in platform.scala) to StreamEffect #1460 #1772
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
Conversation
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.
Thanks for picking this up @jsilva! This has to stay a stream emitting chunks, otherwise performance will plummet.
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.
Thanks @jsilva. Could you revert the unrelated formatting changes?
| } else { | ||
| a.toByte | ||
| } | ||
| val buf = Array.ofDim[Byte](chunkSize) |
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.
The buf has to be re-created every time pull runs, or we'll be mutating chunks that have already been emitted.
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.
Updated this
| } | ||
| val buf = Array.ofDim[Byte](chunkSize) | ||
| def pull(): Chunk[Byte] = { | ||
| val bytesRead = is.read(buf) |
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.
this needs to be wrapped in try/catch and should catch IOException and re-throw it using StreamEffect.fail
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.
updated, thanks for help
|
|
||
| final def fromInputStream(is: InputStream): StreamEffect[Any, Nothing, Byte] = | ||
| StreamEffect[Any, Nothing, Byte] { | ||
| Managed.effectTotal { |
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.
This is not a total effect, I can see Managed.makeEffect which is probably more appropriate here.
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.
Well the Managed only returns a thunk that, so in that regard it should be total
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.
This is how we treated all StreamEffect code so far.
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.
Awesome. This is great.
The only thing we lost during this porting is the use of the Blocking executor, which I will take care of in #1483.
* Port ZStream.fromInputStream (the one in platform.scala) to StreamEffect zio#1460 * Port ZStream.fromInputStream (the one in platform.scala) to StreamEffect zio#1460 * code review updates * code review updates * moved buffer to pull call, to avoid mutation * catch exception and use StreamEffectChunk
* Migrate StackBoolSpec to ZIO Tests (#1647) * Fix build issues introduced by bundling (#1754) * #1647 - converted SerializableSpec to ZTest (#1769) * Move PlatformLive.ExecutorUtil to Executor companion object. private zio.internal.Sync (#1770) * Modified dies signature (#1768) * Modified dies signature * Added type parameter * Removed type parameter * Restart schedule on end in ZStream#scheduleWith (#1767) * Restart schedule on end * Remove unused state, add docs * Port ZStream.fromInputStream to StreamEffect #1460 (#1772) * Port ZStream.fromInputStream (the one in platform.scala) to StreamEffect #1460 * Port ZStream.fromInputStream (the one in platform.scala) to StreamEffect #1460 * code review updates * code review updates * moved buffer to pull call, to avoid mutation * catch exception and use StreamEffectChunk * Specify that this fiber will be "inner interrupted" on joining an interrupted Fiber (#1774) * #1647: Migrate all tests to ZIO Test: Platform spec (#1775) * Migrate Fiber tests to ZIO Tests (#1647) (#1777) * Update zio-interop-java to 1.1.0.0-RC5 (#1781) * Update fs2-core to 2.0.1 (#1779) * Update sbt-pgp to 1.1.2 (#1780) * Update zio-interop-monix to 3.0.0.0-RC6 (#1782) * updated resources page to add my examples (#1783) * Migrate ZScheduleSpec to ZIO Tests (#1647)
Pull request for #1460