5

I'm writing a web based application (large cargo aircraft weight and balance) in which the user enters pallet weights. When an individual pallet weight is entered, a number of checks have to be made to determine if that weight can be accepted. The checks are all relatively trivial in terms of compute cycles required; one is not. As I understand it, JavaScript is single-threaded, which I take to mean that if the user starts to enter a weight in another pallet position, he's going to be locked out until the previous weight is fully processed.

I can't afford to have the user waiting every time he enters a weight (which they don't have to do at the moment as the app currently doesn't make that last check properly). Currently I'm thinking of not doing the final compute-intensive step until all weights are entered and the user signifies so by clicking on a button. However, this will deprive the user of immediate feedback as to which weight initially triggered the problem, a problem in which multiple weights may contribute, and which is going to be hard to sort out if they have to wait until the last.

My Google searches on the topic have been somewhat useful, but I'm asking here for possible ideas for an up-to-date solution to the dilemma. Any suggestions are most welcome. The context of the problem can be observed by going to http://terryliittschwager.com/WB/JWB.php and selecting an aircraft.

4

2 回答 2

2

如果您想做客户端,我建议您研究 WebWorkers。它们在与主 (DOM) JS 线程不同的线程上运行。并非所有浏览器都支持(当然),但目前在 Chrome、FF、Safari 和 IE 10 中受支持。

编辑:WebWorkers的 MDN是一个很好的起点。

于 2012-05-23T20:28:01.733 回答
1

您可以将 Ajax 用于长的一个,而 javascript 用于其余的。或者如果可能的话,分解计算,一次做一点。 http://www.sitepoint.com/multi-threading-javascript/

于 2012-05-23T20:30:40.823 回答