]> gerrit.simantics Code Review - simantics/platform.git/commitdiff
(refs #7607) Async module for running functions asynchronously 06/1206/2
authorHannu Niemistö <hannu.niemisto@semantum.fi>
Tue, 7 Nov 2017 14:23:12 +0000 (16:23 +0200)
committerHannu Niemistö <hannu.niemisto@semantum.fi>
Tue, 7 Nov 2017 14:24:28 +0000 (16:24 +0200)
Change-Id: I4870aefa0c965bd0cf4ada19c01fa9b01efca171

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();
+    }
+}