0
var globalArray = [];

This callback gets fired up to 100 times per second

function EventCallback(param) {

globalArray.push(param);

}

Main part of the program where I process the list of items.

What happens if the callback gets fired while in the middle of modifying the array here?

while(globalArray.length > 0) 
{

ProcessListItem(globalArray.shift());

}

The issue I'm running into is that Firefox Spidermonkey javascript engine is sometimes bugging out (race condition/threading issue?) and telling me that globalArray.push is not a function or other strange errors.

What I'm trying to achieve is to have the callback add items to a list so I can process them later. Is there any better way to code this? I'm new to this so any advice is appreciated. Thanks

1
  • Your callback can't fire while in your while loop because JavaScript is single threaded. Commented Feb 20, 2013 at 18:07

1 Answer 1

5

It will not happen, since JavaScript runs single threaded in your browser. The event will only be fired if the browser has nothing else to do.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.