UPDATE on 2017-03-27
asyncmeans the library or API will call you in the future, there are some styles of async,
- non-blocking means you must query result by yourself, using
- They look like call very quickly, because they always return before all codes are executed.
UPDATE on 2017-03-29
- In nearly all cases, any function that calls a coroutine must be a coroutine itself, and use the yield keyword in the call. When you are overriding a method defined in a superclass, consult the documentation to see if coroutines are allowed (the documentation should say that the method “may be a coroutine” or “may return a Future”) ***
This is the first part of Tornado studying project.
Tornado can be roughly divided into four major components:
- A web framework (including RequestHandler which is subclassed to create web applications, and various supporting classes).
- Client- and server-side implementions of HTTP (HTTPServer and AsyncHTTPClient).
- An asynchronous networking library (IOLoop and IOStream), which serve as the building blocks for the HTTP components and can also be used to implement other protocols.
- A coroutine library (tornado.gen) which allows asynchronous code to be written in a more straightforward way than chaining callbacks.
Tornado uses a signle-threaded event loop.This means that all application code should aim to be asynchronous and non-blocking because only one operation can be active at a time.
There are many styles of asynchronous interfaces:
- Callback argument
- Return a placeholder (Future, Promise, Deferred)
- Deliver to a queue
- Callback registry (e.g. POSIX signals)
There is no free way to make a synchronous function asynchronous in a way that is transparent to its callers.
Coroutines are the recommended way to write asynchronous code in Tornado
A function containing yield is a generator. All generators are asynchronous; when called they return a generator object instead of running to completion.