DEV Community

Discussion on: Practical Async JavaScript

Collapse
 
gauravchandra profile image
Gaurav Chandra

this is a great article. however, there is an opinion in the dev community that we should not be using async/await as it blocks the thread. Instead we should use observables. Care to shed a light on this?

Collapse
 
oculus42 profile image
Samuel Rouse

Async/await is non-blocking. They are literally a different way of writing promises, and if it help you can think of Promises as roughly equivalent to observables that are guaranteed to will only ever produce one event. They cover different use cases, but they are async.

Observables may be used to initiate promises, e.g. the classic RxJS Wikipedia search demo from MIX11, but the promise is still non-blocking

I would appreciate it if you have any links to information on this topic, in case I am misunderstanding or missing context.

Collapse
 
deepakbaid profile image
deepakbaid97

Using await is what blocks the thread. I think that's what he meant

Thread Thread
 
brandon_4ac813c611a5340fe profile image
Brandon

Seconding what @oculus42 said: unless there's a misunderstanding or missing context, this is still untrue.

Await is not blocking. It defers execution of subsequent code until after the awaited code completes, but it doesn't block the thread.