Skip to content
This repository was archived by the owner on Sep 7, 2023. It is now read-only.

Commit 03bb8f7

Browse files
author
Alex Walker
authored
Raise StopIteration when iterating over an already-completed Stream (typedb#185)
## What is the goal of this PR? Previously, iterating over an already-completed Stream would stall. Now, we instead raise a `StopIteration` error. ## What are the changes implemented in this PR? Raise StopIteration when iterating over an already-completed Stream
1 parent 147ae7f commit 03bb8f7

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

grakn/rpc/stream.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,14 @@ def __init__(self, transaction, request_id: str, transform_response: Callable[[t
3434
self._request_id = request_id
3535
self._transform_response = transform_response
3636
self._current_iterator = None
37+
self._done = False
3738

3839
def __iter__(self):
3940
return self
4041

4142
def __next__(self):
43+
if self._done:
44+
raise StopIteration()
4245
if self._current_iterator is not None:
4346
try:
4447
return next(self._current_iterator)
@@ -54,6 +57,7 @@ def __next__(self):
5457
self._transaction._request_iterator.put(continue_req)
5558
return next(self)
5659
elif res_case == Stream._DONE:
60+
self._done = True
5761
raise StopIteration()
5862
elif res_case is None:
5963
raise GraknClientException("The required field 'res' of type 'transaction_proto.Transaction.Res' was not set.")

0 commit comments

Comments
 (0)