Front end developer specialising in JavaScript and React. Experienced in all aspects of modern front end development. Passionate about making accessible, secure and performant software.
Async / await only blocks the code in the specific function. While it's "awaiting", it frees up the main thread so it can do other work. When the code it's waiting on completes (for example, when db.toPublic() has completed its asynchronous operation), and when the main thread is free again, execution inside that function resumes. If it hits another "await" statement, the process repeats (it frees up the main thread and waits for the asynchronous operation to complete).
It actually uses promises behind the scenes, so it has the same effect. In the examples above with the .then and async, they both do the same thing and handle the main thread the same way.
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
You're welcome. I'm glad it's helpful :).
Async / await only blocks the code in the specific function. While it's "awaiting", it frees up the main thread so it can do other work. When the code it's waiting on completes (for example, when
db.toPublic()
has completed its asynchronous operation), and when the main thread is free again, execution inside that function resumes. If it hits another "await" statement, the process repeats (it frees up the main thread and waits for the asynchronous operation to complete).It actually uses promises behind the scenes, so it has the same effect. In the examples above with the
.then
andasync
, they both do the same thing and handle the main thread the same way.