Skip to content

Commit 1468453

Browse files
make try_recv throw on closed channel
1 parent 04ce212 commit 1468453

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

src/handlers.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ use zenoh::handlers::{CallbackParameter, IntoHandler};
2323

2424
use crate::{
2525
macros::{import, py_static},
26-
utils::{generic, short_type_name, IntoPyErr, IntoPyResult, IntoPython, IntoRust},
26+
utils::{generic, short_type_name, IntoPyErr, IntoPython, IntoRust},
2727
ZError,
2828
};
2929

@@ -283,7 +283,10 @@ fn try_recv<T: IntoPython, E: IntoPyErr + Send>(
283283
py: Python,
284284
f: impl FnOnce() -> Result<T, E> + Send,
285285
) -> PyResult<PyObject> {
286-
Ok(py.allow_threads(f).into_pyres()?.into_pyobject(py))
286+
match py.allow_threads(f) {
287+
Ok(obj) => Ok(obj.into_pyobject(py)),
288+
Err(err) => Err(err.into_pyerr()),
289+
}
287290
}
288291

289292
fn recv<T: IntoPython, E: IntoPyErr + Send>(
@@ -319,7 +322,7 @@ impl<T: IntoPython + CallbackParameter> Receiver for RustHandler<DefaultHandler,
319322
}
320323

321324
fn try_recv(&self, py: Python) -> PyResult<PyObject> {
322-
try_recv(py, || PyResult::Ok(self.handler.try_recv().ok()))
325+
try_recv(py, || self.handler.try_recv().map_err(DeadlineError::Error))
323326
}
324327

325328
fn recv(&self, py: Python) -> PyResult<PyObject> {

0 commit comments

Comments
 (0)