我有幾行代碼,我想要在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