作者eight0 (自宅程式猿)
看板Web_Design
标题Re: [问题] Javascript利用TextArea当作Console
时间Mon Jul 20 19:47:39 2015
实作 thread,大概有这三种方法︰
1. 分段做
function createBatchProcess() {
var running, keys;
function start() {
if (running) {
return;
}
running = true;
...
...
keys = Object.keys(books);
setTimeout(next);
}
function next() {
if (!keys.length) {
return stop();
}
var key = keys.shift();
print(books[key]);
BatchTextImport(books[key], Word_Application);
setTimeout(next);
}
function stop() {
Word_Application.Quit();
Word_Application = null;
running = false;
}
return {
start: start
};
}
$("ProcessGo").click(createBatchProcess().start);
2. 用 generator
function* genProcess() {
...
...
for (var key in books) {
yield print(books[key]);
BatchTextImport(books[key], Word_Application);
}
Word_Application.Quit();
Word_Application = null;
}
var process = genProcess();
$("ProcessGo").click(function do(){
if (!process.next().done) {
setTimeout(do);
}
});
3. 用 Web Worker:
http://is.gd/b0mcrA
--
(* ̄▽ ̄)/‧★*"`'*-.,_,.-*'`"*-.,_☆,.-*`
http://i.imgur.com/oAd97.png
--
※ 发信站: 批踢踢实业坊(ptt.cc), 来自: 1.160.81.100
※ 文章网址: https://webptt.com/cn.aspx?n=bbs/Web_Design/M.1437392863.A.148.html
1F:推 iwasawasin: 感谢E大帮忙,请问若是E大比较推荐哪一种? 07/21 13:36
2F:→ iwasawasin: Generator我查了资料後发现,这方法好像很实用,正在 07/21 13:40
3F:→ iwasawasin: 考虑从这边下手,不过可能要花点时间理解! 07/21 13:40
4F:→ iwasawasin: 另外,IE好像不支援Generator的方法,可是Chrome好像 07/21 13:57
5F:→ iwasawasin: 也不支援ActiveX Q___Q 07/21 13:57
6F:→ eight0: 可以的话用 Web Worker。其它两者只是在 js 中模拟,只有 07/22 08:24
7F:→ eight0: worker 是系统级的 multithread。不过既然你只是要做 07/22 08:24
8F:→ eight0: batch,挑自己方便的就行了 07/22 08:24