I have several buttons and each calculates some numbers and displays it on screen. Different buttons take differnet amount of time to finish calculation. In my current implementation, if I click on a button and then click on a different button before the first one finishes, the result from the second button is displayed only after the first one finishes. How can I modify this that as soon as I click the second button, it stops the calculation initiated by the first button and continues with its calculation?
HTML
<input type=button value=One onclick=displayNumber(1)>
<input type=button value=Two onclick=displayNumber(2)>
....
JavaScript
function displayNumber(id) {
alert(calculateAwesomeNumber(id));
}
This may be not possbile in JavaScript as it is single-threaded and only one function can be running at any time. Am I correct?