我有几行代码,我想要在Javascript中异步运行,以便它不会减慢我的主算法。看到这个伪代码:Javascript:如何编写一个将被异步执行的函数?
//main algorithm with critical code that should run as soon as possible
...
...
runInParallel(function(){
//time consuming unimportant code to shows some progress feedback to user
...
}
//the rest of the time critical algorithm
...
...
runInParallel(function(){
//time consuming unimportant code to shows some progress feedback to user
...
}
//and so on and so forth
我搜索#2为如何使用JavaScript编写异步代码,但下面的问题是不是与我相似:
- how to run a javascript function asynchronously, without using setTimeout?:它是关于服务器端
- Loading javascript asynchronously - How to do callbacks?:这是关于加载源代码
我想我可以使用计时器来达到此目的。我所需要的是函数runInParallel()的主体,如果可能的话,它可以有效地与我的主算法并行运行代码。任何人?
较低优先?我怀疑是否有这种方式 – 2012-03-08 08:53:17
搜索网络工作者 – user123444555621 2012-03-08 08:53:37