Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions core/shared/src/main/scala/zio/ZInputStream.scala
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ object ZInputStream {
ZIO.attemptBlockingIO {
val b: Array[Byte] = new Array[Byte](n)
val count = is.read(b)
if (count == -1) ZIO.fail(None) else ZIO.succeed(Chunk.fromArray(b).take(count))
if (count == -1) Exit.failNone else ZIO.succeed(Chunk.fromArray(b).take(count))
}.mapError { case e: IOException =>
Some(e)
}.flatten
Expand All @@ -49,7 +49,7 @@ object ZInputStream {
val idata = new Array[Byte](bufferSize);
var count = is.read(idata, 0, idata.length)

if (count == -1) ZIO.fail(None)
if (count == -1) Exit.failNone
else {
var countTotalBytes = 0
var data = idata
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ object ZStreamPlatformSpecificSpec extends ZIOBaseSpec {
global.execute { () =>
// 1st consumed by sink, 2-6 – in queue, 7th – back pressured
(1 to 7).foreach(i => cb(refCnt.set(i) *> ZIO.succeed(Chunk.single(1))))
cb(refDone.set(true) *> ZIO.fail(None))
cb(refDone.set(true) *> Exit.failNone)
}
None
},
Expand Down Expand Up @@ -89,7 +89,7 @@ object ZStreamPlatformSpecificSpec extends ZIOBaseSpec {
for {
result <- ZStream
.asyncZIO[Any, Nothing, Int] { k =>
global.execute(() => k(ZIO.fail(None)))
global.execute(() => k(Exit.failNone))
ZIO.unit
}
.runCollect
Expand All @@ -104,7 +104,7 @@ object ZStreamPlatformSpecificSpec extends ZIOBaseSpec {
global.execute { () =>
// 1st consumed by sink, 2-6 – in queue, 7th – back pressured
(1 to 7).foreach(i => cb(refCnt.set(i) *> ZIO.succeed(Chunk.single(1))))
cb(refDone.set(true) *> ZIO.fail(None))
cb(refDone.set(true) *> Exit.failNone)
}
ZIO.unit
},
Expand Down Expand Up @@ -138,7 +138,7 @@ object ZStreamPlatformSpecificSpec extends ZIOBaseSpec {
for {
result <- ZStream
.asyncScoped[Any, Nothing, Int] { k =>
global.execute(() => k(ZIO.fail(None)))
global.execute(() => k(Exit.failNone))
ZIO.unit
}
.runCollect
Expand All @@ -153,7 +153,7 @@ object ZStreamPlatformSpecificSpec extends ZIOBaseSpec {
global.execute { () =>
// 1st consumed by sink, 2-6 – in queue, 7th – back pressured
(1 to 7).foreach(i => cb(refCnt.set(i) *> ZIO.succeed(Chunk.single(1))))
cb(refDone.set(true) *> ZIO.fail(None))
cb(refDone.set(true) *> Exit.failNone)
}
ZIO.unit
},
Expand Down Expand Up @@ -193,7 +193,7 @@ object ZStreamPlatformSpecificSpec extends ZIOBaseSpec {
for {
result <- ZStream
.asyncInterrupt[Any, Nothing, Int] { k =>
global.execute(() => k(ZIO.fail(None)))
global.execute(() => k(Exit.failNone))
Left(ZIO.succeed(()))
}
.runCollect
Expand All @@ -209,7 +209,7 @@ object ZStreamPlatformSpecificSpec extends ZIOBaseSpec {
global.execute { () =>
// 1st consumed by sink, 2-6 – in queue, 7th – back pressured
(1 to 7).foreach(i => cb(refCnt.set(i) *> ZIO.succeed(Chunk.single(1))))
cb(refDone.set(true) *> ZIO.fail(None))
cb(refDone.set(true) *> Exit.failNone)
}
Left(ZIO.unit)
},
Expand Down
2 changes: 1 addition & 1 deletion streams/js/src/main/scala/zio/stream/platform.scala
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ private[stream] trait ZStreamPlatformSpecificConstructors {
)
)
)
.on("end", () => cb(ZIO.fail(None)))
.on("end", () => cb(Exit.failNone))
.on("error", (err: js.Dynamic) => cb(ZIO.fail(Some(new Throwable(err.toString)))))
}
}
Expand Down
4 changes: 2 additions & 2 deletions streams/jvm/src/main/scala/zio/stream/platform.scala
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ private[stream] trait ZStreamPlatformSpecificConstructors {
ZStream.repeatZIOChunkOption(
for {
bytesRead <- ZIO.attempt(channel.read(reusableBuffer)).asSomeError
_ <- ZIO.fail(None).when(bytesRead == -1)
_ <- Exit.failNone.whenDiscard(bytesRead == -1)
chunk <- ZIO.succeed {
reusableBuffer.flip()
Chunk.fromByteBuffer(reusableBuffer)
Expand Down Expand Up @@ -280,7 +280,7 @@ private[stream] trait ZStreamPlatformSpecificConstructors {
bufArray <- ZIO.succeed(Array.ofDim[Char](chunkSize))
bytesRead <- ZIO.attemptBlockingIO(reader.read(bufArray)).asSomeError
chars <- if (bytesRead < 0)
ZIO.fail(None)
Exit.failNone
else if (bytesRead == 0)
ZIO.succeed(Chunk.empty)
else if (bytesRead < chunkSize)
Expand Down
4 changes: 2 additions & 2 deletions streams/native/src/main/scala/zio/stream/platform.scala
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ private[stream] trait ZStreamPlatformSpecificConstructors {
ZStream.repeatZIOChunkOption(
for {
bytesRead <- ZIO.attempt(channel.read(reusableBuffer)).asSomeError
_ <- ZIO.fail(None).when(bytesRead == -1)
_ <- Exit.failNone.when(bytesRead == -1)
chunk <- ZIO.succeed {
reusableBuffer.flip()
Chunk.fromByteBuffer(reusableBuffer)
Expand All @@ -246,7 +246,7 @@ private[stream] trait ZStreamPlatformSpecificConstructors {
bufArray <- ZIO.succeed(Array.ofDim[Char](chunkSize))
bytesRead <- ZIO.attemptBlockingIO(reader.read(bufArray)).asSomeError
chars <- if (bytesRead < 0)
ZIO.fail(None)
Exit.failNone
else if (bytesRead == 0)
ZIO.succeed(Chunk.empty)
else if (bytesRead < chunkSize)
Expand Down
13 changes: 8 additions & 5 deletions streams/shared/src/main/scala/zio/stream/ZStream.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3490,10 +3490,13 @@ final class ZStream[-R, +E, +A] private (val channel: ZChannel[R, Any, Any, Any,
*/
def toPull(implicit trace: Trace): ZIO[R with Scope, Nothing, ZIO[R, Option[E], Chunk[A]]] =
channel.toPull.map { pull =>
pull.mapError(error => Some(error)).flatMap {
case Left(done) => ZIO.fail(None)
case Right(elem) => ZIO.succeed(elem)
}
pull.foldZIO(
success = {
case Left(done) => Exit.failNone
case Right(elem) => Exit.succeed(elem)
},
failure = error => Exit.fail(Some(error))
)
}

/**
Expand Down Expand Up @@ -4318,7 +4321,7 @@ object ZStream extends ZStreamPlatformSpecificConstructors {
bufArray <- ZIO.succeed(Array.ofDim[Byte](chunkSize))
bytesRead <- ZIO.attemptBlockingIO(is.read(bufArray)).asSomeError
bytes <- if (bytesRead < 0)
ZIO.fail(None)
Exit.failNone
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe better done as a separate PR, but maybe we should store Exit.succeed(Chunk.empty) in a val and use it below here

Copy link
Member Author

Choose a reason for hiding this comment

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

Hehe: #9360

Copy link
Contributor

Choose a reason for hiding this comment

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

Wow 😆

else if (bytesRead == 0)
ZIO.succeed(Chunk.empty)
else if (bytesRead < chunkSize)
Expand Down
Loading