【发布时间】:2012-03-08 08:51:06
【问题描述】:
我有几行代码我想在 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
我在 Stackoverflow 上搜索了如何用 Javascript 编写异步代码,但以下问题与我的不同:
- how to run a javascript function asynchronously, without using setTimeout?: 是关于服务器端的
- Loading javascript asynchronously - How to do callbacks?: 加载源代码
我想我可以为此使用计时器。我想要的只是函数 runInParallel() 的主体,它与我的主算法并行有效地运行代码,如果可能的话,优先级较低。有人吗?
【问题讨论】:
-
优先级较低?我怀疑有没有这样的方法
标签: javascript multithreading asynchronous web-worker