button1
<button>button 1</button>
<button>button 2</button>
<button>button 3</button>
<button>button 4</button>
Let's say I have multiple button on a page. When you click on them they turn red. This transformation takes awhile (5-30 seconds).
I implemented an Ajax call that starts the transformation when a button is clicked, it turns the button into red when completed. The button turns red only after the server has responded.
I'm trying to implement a mechanism for ensuring that only one transformation is processed at a time. That is, if the user clicks multiple buttons there is only ever one Ajax call that is being processed at a given time.
I was thinking about implementing a Queue mechanism pushing the ajax call in an array when the user click on a button and run each one recursively. But I don't know how to do it dynamically, meaning, how to tell to my function: 'hey the user add a new item in the queue' please proceed.
I have to connect my array of ajax calls and my function that proceeds ajax calls once at a time. My function should listen to any events occurring in the array.
Any other idea?
Thanks!