Merge "(refs #7607) Async module for running functions asynchronously"
authorHannu Niemistö <hannu.niemisto@semantum.fi>
Tue, 7 Nov 2017 14:44:31 +0000 (16:44 +0200)
committerGerrit Code Review <gerrit2@www.simantics.org>
Tue, 7 Nov 2017 14:44:31 +0000 (16:44 +0200)
bundles/org.simantics.scl.runtime/scl/Async.scl [new file with mode: 0644]
bundles/org.simantics.scl.runtime/src/org/simantics/scl/runtime/utils/AsyncUtils.java [new file with mode: 0644]

diff --git a/bundles/org.simantics.scl.runtime/scl/Async.scl b/bundles/org.simantics.scl.runtime/scl/Async.scl
new file mode 100644 (file)
index 0000000..c47f457
--- /dev/null
@@ -0,0 +1,2 @@
+importJava "org.simantics.scl.runtime.utils.AsyncUtils" where
+    runAsync :: (<Proc> a) -> <Proc> ()
\ No newline at end of file
diff --git a/bundles/org.simantics.scl.runtime/src/org/simantics/scl/runtime/utils/AsyncUtils.java b/bundles/org.simantics.scl.runtime/src/org/simantics/scl/runtime/utils/AsyncUtils.java
new file mode 100644 (file)
index 0000000..fcd8a47
--- /dev/null
@@ -0,0 +1,22 @@
+package org.simantics.scl.runtime.utils;
+
+import org.simantics.scl.runtime.SCLContext;
+import org.simantics.scl.runtime.function.Function;
+import org.simantics.scl.runtime.tuple.Tuple0;
+
+public class AsyncUtils {
+    public static void runAsync(Function f) {
+        SCLContext context = SCLContext.getCurrent();
+        new Thread() {
+            @Override
+            public void run() {
+                SCLContext.push(context);
+                try {
+                    f.apply(Tuple0.INSTANCE);
+                } finally {
+                    SCLContext.pop();
+                }
+            }
+        }.start();
+    }
+}