Recently the programs I write are mainly Python, JavaScript, and TypeScript. After adopting Python3 and the new version of Tornado, asyncio seems forced upon us. In this article I’ll share my views on the async/await keywords. Since I’m an ordinary developer, these views may be rather superficial.
Forgetting await
The first problem: in Python, when calling an async function you may forget the await. Not only Python — JavaScript has this phenomenon too; it’s easy to overlook while coding.
Perhaps careful readers won’t forget. But if you do forget, the code only errors when executed. For this problem I especially suggest writing test cases, to prevent carelessly dropping the await.
As far as I feel, strongly typed languages are more suitable for async and await, because if you don’t await,
the compiler directly gives an error. For example in TypeScript I’ve basically never dropped an await, because the compiler errors immediately.
Learning and Usage Costs
As a developer, I don’t think async/await has a low learning cost. In one of my blog posts I shared learning about coroutines and Asyncio — you still need to understand yield.
Moreover, after introducing new keywords, almost every function along the entire call chain of an async function needs async added.
Considering Python’s conciseness, I personally still dislike adding async/await.
For monkey patch, its complex logic is better hidden and it’s non-invasive to the original code.
Used correctly, ordinary developers needn’t worry about any async/await problems at all.
Summary
The business I take over should rarely depend on asyncio, and I don’t plan to introduce it.
For personal projects, I prefer golang and TypeScript — after all, strongly typed languages are much easier to maintain.
If asyncio must be used, it should only be used on specific libraries.
Appendix
While searching, I found Reddit also had a related discussion: Should I stick with asyncio or return to gevent.
.png)