In trying to find a way to run some functions that are stored in an array like the one below, I produced the following code.
This works fine, but sometimes it seems to execute a function before a previous one is finished.
How do I prevent functions being executed in the code below before previous are finished?
An example of an array with several function "calls" and parameters
["A3",[6]],["B1",["TEST",4,13]],["A10",[2]],["A7",[1,5]]
The for loop that executes each function call from above array
function routineConverter(v){
var routines = JSON.parse('[' + v + ']');
for ( var i=0; i < routines.length ; i++ ){
switch (routines[i][0]) {
case 'A1':
routines[i] = A1( routines[i][1] );
break;
case 'A2':
routines[i] = A2( routines[i][1] );
break;
case 'A3':
routines[i] = A3( routines[i][1] );
break;
case 'A4':
routines[i] = A4( routines[i][1] );
break;
case 'A5':
routines[i] = A5( routines[i][1] );
break;
case 'A6':
routines[i] = A6( routines[i][1] );
break;
case 'A7':
routines[i] = A7( routines[i][1] );
break;
case 'A8':
routines[i] = A8( routines[i][1] );
break;
case 'A9':
routines[i] = A9( routines[i][1] );
break;
case 'A10':
routines[i] = A10( routines[i][1] );
break;
case 'B1':
routines[i] = B1( routines[i][1] );
break;
case 'B2':
routines[i] = B2( routines[i][1] );
break;
case 'E':
routines[i] = conditionalAction( routines[i][1] );
break;
case 'X1':
//console.log(routines[i][1]);
routines[i] = REMOVE(routines[i][1] ); //B1( routines[i][1] );
break;
}
}
var a = [routines];
}
Example of a function:
function A1(p) {
$('#tbl tr td:nth-child(' + parseInt(p) + ')').after('<td></td>');
}