Skip to content

Commit 0d1402a

Browse files
authored
Use readNextAsync for reader.read_next() (#125)
1 parent 0028893 commit 0d1402a

File tree

1 file changed

+1
-27
lines changed

1 file changed

+1
-27
lines changed

src/reader.cc

Lines changed: 1 addition & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -22,33 +22,7 @@
2222
namespace py = pybind11;
2323

2424
Message Reader_readNext(Reader& reader) {
25-
Message msg;
26-
Result res;
27-
28-
// TODO: There is currently no readNextAsync() version for the Reader.
29-
// Once that's available, we should also convert these ad-hoc loops.
30-
while (true) {
31-
Py_BEGIN_ALLOW_THREADS
32-
// Use 100ms timeout to periodically check whether the
33-
// interpreter was interrupted
34-
res = reader.readNext(msg, 100);
35-
Py_END_ALLOW_THREADS
36-
37-
if (res != ResultTimeout) {
38-
// In case of timeout we keep calling receive() to simulate a
39-
// blocking call until a message is available, while breaking
40-
// every once in a while to check the Python signal status
41-
break;
42-
}
43-
44-
if (PyErr_CheckSignals() == -1) {
45-
PyErr_SetInterrupt();
46-
return msg;
47-
}
48-
}
49-
50-
CHECK_RESULT(res);
51-
return msg;
25+
return waitForAsyncValue<Message>([&](ReadNextCallback callback) { reader.readNextAsync(callback); });
5226
}
5327

5428
Message Reader_readNextTimeout(Reader& reader, int timeoutMs) {

0 commit comments

Comments
 (0)