1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
| var thread, currentThread;
var complete = false;
var result = 0;
thread = Components.classes["@mozilla.org/thread-manager;1"]
.getService(Components.interfaces.nsIThreadManager)
.newThread(0);
currentThread = Components.classes["@mozilla.org/thread-manager;1"]
.getService(Components.interfaces.nsIThreadManager)
.currentThread;
var backgroundTask = {
run: function() {
result = myComponent.myFunction();
complete = true;
}
}
thread.dispatch(backgroundTask, thread.DISPATCH_NORMAL);
while(!complete){
currentThread.processNextEvent(true);
}
//do something with result
... |