zlacker

[return to "The bane of my existence: Supporting both async and sync code in Rust"]
1. toolto+sh[view] [source] 2024-01-19 23:36:57
>>lukast+(OP)
The comment threads here discuss async in many different languages: Rust, Go, JavaScript, Python. Can somebody knowledgeable describe how they are subtly different between languages? Why are they painful in some but not in others?

Is there already an article that describes this well?

◧◩
2. Too+HU[view] [source] 2024-01-20 07:00:06
>>toolto+sh
JS makes it easier because it was always single threaded and never had any sync IO to begin with.

This means, before async existed, any library doing IO had to be based on callbacks. Then came Promises, which are essentially glorified callbacks and then came async which can be seen syntax sugar for Promises.

So you will never see synchronous code that depends on an asynchronous result. The concept of sync code waiting for something just never existed in JavaScript. Instead you wake up your sync functions with Promise.then()-callbacks and that same mechanism bridges async functions.

It’s also very rare to have compute heavy sync code in JS so there is rarely any need to run it multi threaded.

[go to top]