In my application, I have a submitSuccesscallback function, which will be triggered from my own JS library when submit was successful.
Within submitSuccesscallback, I am first displaying a loader and doing some initialization operations.
function submitSuccesscallback(){
showLoadingIndicator(); // has code a display loader
doSubmitSuccessOperations();// has code to do some app specific operations
}
here doSubmitSuccessOperations() is taking around 5 secs for complete execution.
Now my problem is above code does n't display loader (i.e ui changes from showLoadingIndicator()) upto 5 secs after I get the submitSuccesscallback().
If I change submitSuccesscallback() like below, I am able to see loader immediately after I trigger submitSuccesscallback().
function submitSuccesscallback(){
showLoadingIndicator(); // has code a display loader
setTimeout(doSubmitSuccessOperations, 1000);
}
Now what I would like to know is:
does setTimeout makes my
doSubmitSuccessOperations()run in background?I clearly sense that
doSubmitSuccessOperations()is blocking UI operation, is there any concept of UI thread and background thread in JS?Any other alternative for
setTimeoutabove?
async: falseAJAX request.doSubmitSuccessOperationsfunction in another thread.setTimeout(fn, 0);would also work.