Skip to content

Commit

Permalink
Improve detection of just-started generator
Browse files Browse the repository at this point in the history
  • Loading branch information
cjrh committed Oct 23, 2021
1 parent deea651 commit bbd6079
Showing 1 changed file with 8 additions and 16 deletions.
24 changes: 8 additions & 16 deletions excitertools.py
Original file line number Diff line number Diff line change
Expand Up @@ -3814,15 +3814,11 @@ def send(self, collector: Generator, close_collector_when_done=False) -> "None":
Note that Iter.send_ is a sink, so no further chaining is allowed.
"""
if inspect.getgeneratorstate(collector) == 'GEN_CREATED':
next(collector)

for v in self:
try:
collector.send(v)
except TypeError as e:
if "just-started generator" in str(e):
next(collector)
collector.send(v)
else: # pragma: no cover
raise
collector.send(v)

if close_collector_when_done:
collector.close()
Expand Down Expand Up @@ -3875,14 +3871,10 @@ def send_also(self, collector: Generator) -> "Iter":
"""
def func(v):
try:
collector.send(v)
except TypeError as e:
if "just-started generator" in str(e):
next(collector)
collector.send(v)
else: # pragma: no cover
raise
if inspect.getgeneratorstate(collector) == 'GEN_CREATED':
next(collector)

collector.send(v)

return self.side_effect(func)

Expand Down

0 comments on commit bbd6079

Please sign in to comment.