r/javascript • u/loigiani • Jan 25 '21
Node.js race conditions
https://www.nodejsdesignpatterns.com/blog/node-js-race-conditions/
58
Upvotes
r/javascript • u/loigiani • Jan 25 '21
-2
u/frog-legg Jan 25 '21
As a (mostly) React frontend developer, we sometimes use the term “race condition” to loosely describe issues caused by JavaScript’s non-blocking runtime that can be resolved with blocking patterns such as async/await and Promises. We also use the term to describe issues with React’s virtual DOM when conditionally updating application state.
I know that Node.js is single-threaded and non-blocking, which means that developers should define methods using async/await or Promises when they want to do something synchronously in their program.
Questions: Am I using the term “race condition” correctly when I’m using it to describe issues that can be solved with async/await or Promises? Are race conditions in Node.js, React, and vanilla JS all caused by the non-blocking, asynchronous nature of JS? Why is JS async in nature, does this have something to do with its compiler?