2 var thread_manager = Cc["@mozilla.org/thread-manager;1"].getService();
4 function thread_callback(run_function) {
5 this.run_function = run_function;
7 thread_callback.prototype = {
8 QueryInterface: generate_QI(Ci.nsIRunnable),
10 this.run_function.call(null);
14 function call_in_thread(thread, func) {
15 thread.dispatch(new thread_callback(func), Ci.nsIEventTarget.DISPATCH_NORMAL);
18 function call_in_new_thread(func, success_cont, error_cont) {
19 var thread = thread_manager.newThread(0);
20 var current_thread = thread_manager.currentThread;
21 call_in_thread(thread, function () {
24 call_in_thread(current_thread, function () {
30 call_in_thread(current_thread, function () {
39 /* Coroutine interface */
40 function in_new_thread(f) {
41 var args = Array.prototype.splice.call(arguments, 1);
42 var cc = yield CONTINUATION;
43 var thread = thread_manager.newThread(0);
44 var current_thread = thread_manager.currentThread;
45 call_in_thread(thread, function () {
47 var result = f.apply(null, args);
48 call_in_thread(current_thread, function () {
53 call_in_thread(current_thread, function () {
59 var result = yield SUSPEND;
60 yield co_return(result);