Search code examples
pythontornado

why tornado TCPClient.connect return a Future object?


In the official docs that says:

class tornado.tcpclient.TCPClient(resolver=None, io_loop=None)

connect(host, port, af=<AddressFamily.AF_UNSPEC: 0>, ssl_options=None, max_buffer_size=None)

Asynchronously returns an IOStream

but

import tornado.gen
import tornado.tcpclient
import tornado.ioloop
@tornado.gen.coroutine
def main():
    return tornado.tcpclient.TCPClient.connect('127.0.0.1', '8888')
result = tornado.ioloop.IOLoop.instance().run_sync(main)

I thought the result is a IOStream object.In fact, It's a Future object.

So, why isn't it a IOStream object ?


Solution

  • the document http://www.tornadoweb.org/en/stable/tcpclient.html says: Asynchronously returns an IOStream (or SSLIOStream if ssl_options is not None).

    in tornado, the asynchronous methods return future object.