I want my code to be executed synchronously in the same order I call the 'asyncFunc' function. The first call needs to finished before executing the next call and so on.
I would like the below sample program to output:
type => slow
type => medium
type => fast
How do I accomplish that?
var asyncFunc = function( type ) {
if( type == 'slow')
{
$timeout( function(){ console.log('type => slow'); }, 10000);
}
else if( type == 'medium')
{
$timeout( function(){ console.log('type => medium'); }, 5000);
}
else if( type == 'fast')
{
$timeout( function(){ console.log('type => fast'); }, 1);
}
}
asyncFunc('slow');
asyncFunc('medium');
asyncFunc('fast');