joe ertaba wrote:
> Hi
>
> Here is my problem, I have a asynchron function (MyAsynchronFun), I
> need it many time in my code, but problem is that I need its output to
> continue my script, here is sample
>
> a = 1;
>
> MyAsynchronFun( function(a) {       
>
>   b = some_return_value_from_MyAsynchronFun;
>   ...
>   MyAsynchronFun( function(b) { 
>   ...
>   c = some_return_value_from_MyAsynchronFun;
>   ...
>
>   })
>                                             
> })
>
> Whereas I need to call this function several times so it make code so
> complex,
>
> Here is what I need
>
> a = 1;
>
> b = MySynchronFun( a );
> ....
> c = MySynchronFun( b );
>
> so I want to convert a asynchron function to synchron one, here is my idea
>
>
> MySynchronFun (a) {
>
>   MyAsynchronFun( function(a) {  .... , cancel_pause()             } );
>
>   PAUSE();
>
>   return  some_return_value_from_MyAsynchronFun;
>
> }
>
>
> There isn't any real pause function for JS, but I wonder if there is
> something like alert() which make script stop without any cpu usage
> and cancel_pause should be something like clicking on OK in alert window
>
> so is there any idea about this kind of pause function ?


If you want to leave it async, your best bet is probably to use
callbacks. For instance:

function abc(){
 ...code part 1...
 setTimeout( function(){MyAsynchronFun(abc_callback, callback_params)} ,
-1);  // call the async function
}

function abc_callback(params)
 ...code part 2...
}

function MyAsynchronFun(callback, callback_params) {
 ...
 setTimeout( function(){callback.apply(this, callback_params)}), -1);
}



_______________________________________________
Project_owners mailing list
[email protected]
https://www.mozdev.org/mailman/listinfo/project_owners

Reply via email to