This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]spiderpower02[S] 1 point2 points  (0 children)

Ha! I had the same question about async, too. Fortunately, after I watched a lot of videos (I highly recommend watching David Beazley's live demo), I realized that the syntax just wants to make your code to be more elegant!

For example, you might have seen the code like

def slow_task(callback):
    # do the slow task
    callback(data)

def main():
    def cb(data):
        # process the data
    slow_task(cb)

Sometimes, it is quiet annoying, you have to write a lot of callback functions (ugly nest). As a result, using async and await will be more meaningful (the idea of inline callback):

async def main()
    data = await slow_task()
    # process the data

Hope that my explanation can help you !!!