return wrapper
-def coroutine(func, replace_callback=True):
+def coroutine(func):
"""Decorator for asynchronous generators.
Any generator that yields objects from this module must be wrapped
`.IOLoop.run_sync` for top-level calls, or passing the `.Future`
to `.IOLoop.add_future`.
+ .. deprecated:: 5.1
+
+ The ``callback`` argument is deprecated and will be removed in 6.0.
+ Use the returned awaitable object instead.
"""
return _make_coroutine_wrapper(func, replace_callback=True)
future = _create_future()
if replace_callback and 'callback' in kwargs:
+ warnings.warn("callback arguments are deprecated, use the returned Future instead",
+ DeprecationWarning, stacklevel=2)
callback = kwargs.pop('callback')
IOLoop.current().add_future(
future, lambda future: callback(future.result()))
self._timeout = self.io_loop.add_timeout(
self.start_time + timeout,
stack_context.wrap(functools.partial(self._on_timeout, "while connecting")))
- self.tcp_client.connect(host, port, af=af,
- ssl_options=ssl_options,
- max_buffer_size=self.max_buffer_size,
- callback=self._on_connect)
+ fut = self.tcp_client.connect(host, port, af=af,
+ ssl_options=ssl_options,
+ max_buffer_size=self.max_buffer_size)
+ fut.add_done_callback(stack_context.wrap(self._on_connect))
def _get_ssl_options(self, scheme):
if scheme == "https":
self.io_loop.remove_timeout(self._timeout)
self._timeout = None
- def _on_connect(self, stream):
+ def _on_connect(self, stream_fut):
+ stream = stream_fut.result()
if self.final_callback is None:
# final_callback is cleared if we've hit our timeout.
stream.close()
yield gen.Task(self.io_loop.add_callback)
raise gen.Return(43)
- f2(callback=(yield gen.Callback('cb')))
+ with ignore_deprecation():
+ 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_pass_callback(self):
- @gen.coroutine
- def f():
- raise gen.Return(42)
- result = yield gen.Task(f)
+ with ignore_deprecation():
+ @gen.coroutine
+ def f():
+ raise gen.Return(42)
+ result = yield gen.Task(f)
self.assertEqual(result, 42)
self.finished = True
def skipIfLocalhostV4(self):
# The port used here doesn't matter, but some systems require it
# to be non-zero if we do not also pass AI_PASSIVE.
- Resolver().resolve('localhost', 80, callback=self.stop)
- addrinfo = self.wait()
+ addrinfo = yield Resolver().resolve('localhost', 80)
families = set(addr[0] for addr in addrinfo)
if socket.AF_INET6 not in families:
self.skipTest("localhost does not resolve to ipv6")