Re: [问题] Javascript利用TextArea当作Console

楼主: eight0 (欸XD)   2015-07-20 19:47:39
实作 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
作者: iwasawasin (Blue)   2015-07-21 13:36:00
感谢E大帮忙,请问若是E大比较推荐哪一种?Generator我查了资料后发现,这方法好像很实用,正在考虑从这边下手,不过可能要花点时间理解!另外,IE好像不支援Generator的方法,可是Chrome好像也不支援ActiveX Q___Q
楼主: eight0 (欸XD)   2015-07-22 08:24:00
可以的话用 Web Worker。其它两者只是在 js 中模拟,只有worker 是系统级的 multithread。不过既然你只是要做batch,挑自己方便的就行了

Links booklink

Contact Us: admin [ a t ] ucptt.com