Skip to content

Commit

Permalink
Implement try_read for PyExtractStream (#146)
Browse files Browse the repository at this point in the history
* Implement try_read for PyExtractStream

* Fix formatting
  • Loading branch information
pschafhalter authored Nov 17, 2020
1 parent 8b5715a commit a5a79c8
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion src/python/py_stream/py_extract_stream.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
use pyo3::{exceptions, prelude::*};

use crate::{dataflow::stream::ExtractStream, python::PyMessage};
use crate::{
dataflow::stream::{errors::TryReadError, ExtractStream},
python::PyMessage,
};

use super::PyReadStream;

Expand Down Expand Up @@ -43,4 +46,16 @@ impl PyExtractStream {
))),
}
}

fn try_read<'p>(&mut self) -> PyResult<Option<PyMessage>> {
match self.extract_stream.try_read() {
Ok(msg) => Ok(Some(PyMessage::from(msg))),
Err(TryReadError::Empty) => Ok(None),
Err(e) => Err(exceptions::Exception::py_err(format!(
"Unable to to read from stream {}: {:?}",
self.extract_stream.get_id(),
e
))),
}
}
}

0 comments on commit a5a79c8

Please sign in to comment.