Deleting Remote Arrays

I know that you can either splice remove an element from an array or delete it with delete . The first approach can cause problems with concurrency, for example. if one thread moves through the array, and the other only moves or splices. delete does not have this problem if forEach is used in the array, since forEach will move through the holes in the array.

However, the array cannot continue to grow forever and will require a radical, potentially causing the same problem as in the case of splicing. It seems like I need a lock, but I would be surprised if Javascript had any possibilities for this. Any thoughts?

+6
source share
2 answers

No, you cannot have a problem with concurrency, as JavaScript is not multithreaded. Even if you use webmasters, you will not have problems because the data is not used (workers exchange messages by sending messages). Even in node.js, your script is not multithreaded.

So just use splice , there is no need to block the array.

+5
source

Javascript is single threaded, so there is no problem.

+1
source

Source: https://habr.com/ru/post/944282/


All Articles