1

I know what does yield do when we write say

while True:
    yield i
    i += 1

But what does it mean when we say

def foo():
    A = yield B

? What would be the value of A then?

The reason why I asked this question is because this is how things are done in tornado: http://www.tornadoweb.org/en/stable/guide/async.html

In Tornado, I see a lot of examples saying

document = yield http_client.fetch('...')

I know document should be the content fetched by the client. By for now I'm trying to understand how it is implemented - I searched for many examples about but couldn't find any one explaining how does "A = yield B" work. By looking Tornado's source code I couldn't understand it myself. Can someone explain it to me?

CBroe
  • 91,630
  • 14
  • 92
  • 150
firstprayer
  • 808
  • 2
  • 11
  • 18
  • With the recent edit, a closer duplicate is http://stackoverflow.com/questions/2022218/what-does-yield-as-assignment-do-myvar-yield – approxiblue Oct 19 '15 at 02:03

0 Answers0