Web Locks API in Node.js and browser

Race condition and deadlocks in asynchronous programming is not something strange but most of developers are not thinking about it and expects a miracle using promises and async/await. Parallel programming have well-known techniques and theory for concurrent computing and state management with different data structures to make them thread-safe. All those primitives like semaphore, mutex, spin-lock, monitors, barriers are usable for asynchronous programming as well but we may simplify them and combine with promises and sync/await to fulfill a concept of resource locking in single-threaded runtime.

While we are getting closer to real parallel programming with multi-threading in JavaScript we have Web locks API as a single and simple abstraction for all needs. It is already available in browsers and can be simply ported to node.js with a hope to reuse it for multi-threading as well with known limitations.

Timur Shemsedinov
Metarhia, Kiev Polytechnic Institute
  • Researcher and lecturer at University "Kiev Polytechnic Institute"
  • Chief Software Architect at Metarhia Technology Stack
  • 25 years in IT, expert in building distributed corporate applications, systems architecture
  • NodeUA, KievNodeJS and HowProgrammingWorks meetups organizer
  • Specialties: cybernetics, programming, DBMS, system analysis, production automation, telemetry, system software, network servers and protocols
  • The author of the Impress application server for Node.js, JSTP and multiple other open source projects
  • Twitter
Sign in
Or by mail
Sign in
Or by mail
Register with email
Register with email
Forgot password?