back

by thunderbong·6y ago·view on hn ↗
Thanks. I really don't have any idea about the asyncio syntatic sugar that you mention. Can you point me to some books / articles?
1 comments
Oh async/await is just python's and javascript's way of executing functions concurrently within the same process. asyncio emerges as a rewrite of a standard library to support this idiom. Browsers that execute javascript ES6 and node v7 onwards have this feature. Instead of passing callbacks to functions and have them executed concurrently, you create a task or future (in python 3.6+) or a Promise (in javascript) and await that. That is very useful because it untangles the callback-inside-callback structure.

There's a comparison between node and python's async/await syntaxes here https://medium.com/@interfacer/intro-to-async-concurrency-in...

For ruby I found this article which shows the gist of what we are trying to accomplish with async/await (we want to gather a bunch of promises and await all their results and have them run concurrently in an event loop so that when one is waiting for IO to complete, the other one takes over and runs) https://www.codeotaku.com/journal/2018-06/asynchronous-ruby/...

I understand async/await as I'm conversant with NodeJs. When you mentioned asyncio, I assumed it be something specific in the Python library.

In case of Ruby, I've found these libraries (ruby gems) to be very useful.

1. Sidekiq - https://github.com/mperham/sidekiq

2. RocketJob - https://github.com/rocketjob/rocketjob

What I'm guessing you're saying is that this kind of behavior is available natively in Python, whereas in Ruby, it is achieved by some roundabout fashion.

These gems are not really related to the asyncio stuff in python. (They're async job runners though... overloaded names can be annoying)

async/await works at a function level in the same process. Asyncio in python is pretty much the async/await from node/js.

Sidekiq alternative in python would be closer to http://www.celeryproject.org/

Yes, async functions are natively available in python3.6+ and node7+, and requires a gem in ruby. Ruby can also use fibers and eventloop to do concurrency using just the standard library, but it is missing the async/await syntactic sugar.