Skip to content

Commit 8e9571e

Browse files
committed
fix unhandled errors in fiber for ZIO2
1 parent da6dd40 commit 8e9571e

File tree

1 file changed

+14
-12
lines changed

1 file changed

+14
-12
lines changed

zio2-zmq/src/main/scala/zio/zmq/ZSocket.scala

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -93,18 +93,20 @@ class ZSocket private (
9393
}
9494
.refineToOrDie[ZMQException]
9595

96-
msg <-
97-
if (msg != null) ZIO.succeed(msg)
98-
else
99-
ZIO
100-
.attemptBlockingCancelable {
101-
val msg = socket.recv(0, canceled)
102-
if (msg != null) msg
103-
else throw new ZMQException(socket.errno())
104-
}(ZIO.attempt(socket.cancel(canceled)).orDie)
105-
.refineToOrDie[ZMQException]
106-
.retryWhile(_.getErrorCode() == ZmqError.EAGAIN)
107-
} yield msg
96+
msg <- if (msg != null) ZIO.succeed(msg)
97+
else {
98+
zio
99+
.ZIO
100+
.attemptBlockingCancelable {
101+
val msg = socket.recv(0, canceled)
102+
if (msg != null) Right(msg)
103+
else Left(new ZMQException(socket.errno()))
104+
}(ZIO.attempt(socket.cancel(canceled)).orDie)
105+
.absolve
106+
.refineToOrDie[ZMQException]
107+
.retryWhile(_.getErrorCode() == ZmqError.EAGAIN)
108+
}
109+
} yield msg
108110

109111
def receiveMsg: ZIO[Any, ZMQException, Msg] = receiveMsgWait(
110112
new AtomicBoolean(false)

0 commit comments

Comments
 (0)