From: Ben Darnell Date: Mon, 4 Mar 2013 01:14:22 +0000 (-0500) Subject: When @return_future's callback is run with no args, don't pass an arg to client callback. X-Git-Tag: v3.0.0~64 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=e9e003eba84652802a349dc5a2eeec5c8102a995;p=thirdparty%2Ftornado.git When @return_future's callback is run with no args, don't pass an arg to client callback. --- diff --git a/tornado/concurrent.py b/tornado/concurrent.py index 2b2d06a38..dd0d015f9 100644 --- a/tornado/concurrent.py +++ b/tornado/concurrent.py @@ -116,6 +116,8 @@ def run_on_executor(fn): return wrapper +_NO_RESULT = object() + def return_future(f): """Decorator to make a function that returns via callback return a `Future`. @@ -154,7 +156,7 @@ def return_future(f): def wrapper(*args, **kwargs): future = Future() callback, args, kwargs = replacer.replace( - lambda value=None: future.set_result(value), + lambda value=_NO_RESULT: future.set_result(value), args, kwargs) def handle_error(typ, value, tb): @@ -185,7 +187,11 @@ def return_future(f): # the callback triggers its exception by calling future.result()). if callback is not None: def run_callback(future): - callback(future.result()) + result = future.result() + if result is _NO_RESULT: + callback() + else: + callback(future.result()) future.add_done_callback(wrap(run_callback)) return future return wrapper diff --git a/tornado/test/concurrent_test.py b/tornado/test/concurrent_test.py index 4e5380e84..7291428d6 100644 --- a/tornado/test/concurrent_test.py +++ b/tornado/test/concurrent_test.py @@ -131,9 +131,17 @@ class ReturnFutureTest(AsyncTestCase): self.assertRaises(ZeroDivisionError, self.wait) def test_no_result_future(self): - self.no_result_future(self.stop) + future = self.no_result_future(self.stop) result = self.wait() self.assertIs(result, None) + # result of this future is undefined, but not an error + future.result() + + def test_no_result_future_callback(self): + future = self.no_result_future(callback=lambda: self.stop()) + result = self.wait() + self.assertIs(result, None) + future.result() # The following series of classes demonstrate and test various styles # of use, with and without generators and futures.