Skip to content

Commit

Permalink
Merge pull request #2549 from garenchan/bugfix-#2448
Browse files Browse the repository at this point in the history
web: Use 'future_add_done_callback' to add callback.
  • Loading branch information
bdarnell committed Dec 15, 2018
2 parents c350dc9 + 9a4a6ce commit 9e4ae9e
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
2 changes: 1 addition & 1 deletion tornado/http1connection.py
Expand Up @@ -492,7 +492,7 @@ def write(self, chunk: bytes) -> "Future[None]":
else:
future = self._write_future = Future()
self._pending_write = self.stream.write(self._format_chunk(chunk))
self._pending_write.add_done_callback(self._on_write_complete)
future_add_done_callback(self._pending_write, self._on_write_complete)
return future

def finish(self) -> None:
Expand Down
12 changes: 12 additions & 0 deletions tornado/test/web_test.py
Expand Up @@ -224,6 +224,13 @@ def get(self):
test.final_return = self.finish()
yield test.final_return

@gen.coroutine
def post(self):
self.write("hello,")
yield self.flush()
test.final_return = self.finish("world")
yield test.final_return

class RenderHandler(RequestHandler):
def create_template_loader(self, path):
return DictLoader({"foo.html": "hi"})
Expand All @@ -243,6 +250,11 @@ def test_finish_method_return_future(self):
self.assertIsInstance(self.final_return, Future)
self.assertTrue(self.final_return.done())

response = self.fetch(self.get_url("/finish"), method="POST", body=b"")
self.assertEqual(response.code, 200)
self.assertIsInstance(self.final_return, Future)
self.assertTrue(self.final_return.done())

def test_render_method_return_future(self):
response = self.fetch(self.get_url("/render"))
self.assertEqual(response.code, 200)
Expand Down

0 comments on commit 9e4ae9e

Please sign in to comment.