You could setup a queue
management system, using the Async
library for example, with something like:
var q = async.queue(function (element, callback) {
// calling the upload task with the element arguments
upload(element)
// calling next task
callback();
}, 1); // we limit the task to 1 at a time
$(document).on('change', 'input[name="' + ID +'[]"]', function() {
// enqueing the task with $(this) as argument
var val = $(this).val()
q.push($(this), function (err) {
// this will be logged when the task is completed
console.log('finished processing ' + val);
});
});
Another way would be to use an array of Promises