diff --git a/tornado/gen.py b/tornado/gen.py index cab9689375..2d20385513 100644 --- a/tornado/gen.py +++ b/tornado/gen.py @@ -400,7 +400,7 @@ def next(self) -> Future: self._running_future = Future() if self._finished: - self._return_result(self._finished.popleft()) + return self._return_result(self._finished.popleft()) return self._running_future @@ -418,9 +418,13 @@ def _return_result(self, done: Future) -> None: raise Exception("no future is running") chain_future(done, self._running_future) + res = self._running_future + self._running_future = None self.current_future = done self.current_index = self._unfinished.pop(done) + return res + def __aiter__(self) -> typing.AsyncIterator: return self