Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get a group of js function running in background

self.showPanel();
self.updateSliderValue();

self.addPoints(1,2,3);

self.setOptions();
self.removeValues();

addPoints method adds points to app and it takes quite lot of time, so I want it running in background and the app goes to setOptions and other functions below it. Please help.

like image 322
H V Avatar asked Dec 14 '25 23:12

H V


1 Answers

javascript is a single thread application, that means there is nothing like a background thread to run.

What you can do is run the function addPoints after the main function is completed, you can use setTimeout to do that

setTimeout(function(){
    self.addPoints(1,2,3);
}, 0)

This will defer the execution of addPoints till the current script executions are over.

like image 149
Arun P Johny Avatar answered Dec 16 '25 11:12

Arun P Johny



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!