]> git.ipfire.org Git - thirdparty/tornado.git/commitdiff
Allow mixes of native coroutines and YieldPoints in gen.multi.
authorBen Darnell <ben@bendarnell.com>
Sun, 4 Oct 2015 00:19:41 +0000 (20:19 -0400)
committerBen Darnell <ben@bendarnell.com>
Sun, 4 Oct 2015 02:28:14 +0000 (22:28 -0400)
tornado/gen.py
tornado/test/gen_test.py

index a1e89dcb23541efc840045cff90c0d8f8c424e95..84a2da68325f243e9889f11bbd9a204f4c0633cf 100644 (file)
@@ -702,6 +702,8 @@ class MultiYieldPoint(YieldPoint):
             children = children.values()
         self.children = []
         for i in children:
+            if not isinstance(i, YieldPoint):
+                i = convert_yielded(i)
             if is_future(i):
                 i = YieldFuture(i)
             self.children.append(i)
index 744dc4046f7c50da22485a7ab267f30a7dbd19c4..1b118f94888dbb4b6374b5d7d9b3ab8ad0b88922 100644 (file)
@@ -732,7 +732,7 @@ class GenCoroutineTest(AsyncTestCase):
 
     @skipBefore35
     @gen_test
-    def test_async_await_mixed_multi(self):
+    def test_async_await_mixed_multi_native_future(self):
         namespace = exec_test(globals(), locals(), """
         async def f1():
             await gen.Task(self.io_loop.add_callback)
@@ -748,6 +748,25 @@ class GenCoroutineTest(AsyncTestCase):
         self.assertEqual(results, [42, 43])
         self.finished = True
 
+    @skipBefore35
+    @gen_test
+    def test_async_await_mixed_multi_native_yieldpoint(self):
+        namespace = exec_test(globals(), locals(), """
+        async def f1():
+            await gen.Task(self.io_loop.add_callback)
+            return 42
+        """)
+
+        @gen.coroutine
+        def f2():
+            yield gen.Task(self.io_loop.add_callback)
+            raise gen.Return(43)
+
+        f2(callback=(yield gen.Callback('cb')))
+        results = yield [namespace['f1'](), gen.Wait('cb')]
+        self.assertEqual(results, [42, 43])
+        self.finished = True
+
     @gen_test
     def test_sync_return_no_value(self):
         @gen.coroutine
@@ -1036,6 +1055,7 @@ class GenYieldExceptionHandler(RequestHandler):
             self.finish('ok')
 
 
+# "Undecorated" here refers to the absence of @asynchronous.
 class UndecoratedCoroutinesHandler(RequestHandler):
     @gen.coroutine
     def prepare(self):