I'm trying to build a scheduling solution in javascript. At the moment i've created an array which is my que, each item has a delayed function in it which will delete itself/the array item.
My question is when i have multiple items in the que deleting itself, whats the best way to conduct this delete. Splice? I'm assuming that Splice relies on index so if i have two simultaneous array items deleting itself i'll run into a race condition where the first one will delete properly but the second will be at the wrong index because the first one spliced the index.
These items are json objects with an embedded function that will contain the self delete.
Any help would be appreciated.
Thanks
EDIT: I should clarify that in order to get the item to be removed i first of have to loop through the que to find the object/the index of the object and then apply the splice.
EDIT 2: This is on a nodejs application
I'm assuming that Splice relies on index so if i have two simultaneous array items deleting itself i'll run into a race condition
No, there is just one thread running javascript, so you won't get into race problems. Therefore it is totally fine to use .splice, but .shift might be more fitting here.
These items are json objects with an embedded function that will contain the self delete.
Following the principle of seperation of concerns, it would be better to let the Queue manage itself.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With