How to do lock in javascript -


i have function called addelementtodom() in javascript, runs loop on array , adds elements 's dom (many of them, takes long time). function being called different events. want make sure every call function waiting previous call finish function before starting addelementtodom. idea doing lock() in c#. couldn't find 1 in javascript. best way implement lock ?

javascript single-threaded don't have concurrency issues. hence, no locks. locks meant resolve concurrency problems.

you might still want logic though, "operation foo shouldn't run until operation bar completed." like:

var operationbariscompleted = false;  function foo() {     if(!operationbariscompleted) {         return;     } // ... }  function bar() {     // ...     operationbariscompleted = true; } 

but i'm writing programming logic you.

however if event-driven need learn work asynchronous code , callbacks. can't teach on answer; plenty of resources on google , stackoverflow.


Comments

Popular posts from this blog

java.util.scanner - How to read and add only numbers to array from a text file -

rewrite - Trouble with Wordpress multiple custom querystrings -