From: Hannu Niemistö Date: Tue, 7 Nov 2017 14:23:12 +0000 (+0200) Subject: (refs #7607) Async module for running functions asynchronously X-Git-Tag: v1.31.0~50^2 X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=commitdiff_plain;h=refs%2Fchanges%2F06%2F1206%2F2;p=simantics%2Fplatform.git (refs #7607) Async module for running functions asynchronously Change-Id: I4870aefa0c965bd0cf4ada19c01fa9b01efca171 --- diff --git a/bundles/org.simantics.scl.runtime/scl/Async.scl b/bundles/org.simantics.scl.runtime/scl/Async.scl new file mode 100644 index 000000000..c47f457ef --- /dev/null +++ b/bundles/org.simantics.scl.runtime/scl/Async.scl @@ -0,0 +1,2 @@ +importJava "org.simantics.scl.runtime.utils.AsyncUtils" where + runAsync :: ( a) -> () \ 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 index 000000000..fcd8a4724 --- /dev/null +++ b/bundles/org.simantics.scl.runtime/src/org/simantics/scl/runtime/utils/AsyncUtils.java @@ -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(); + } +}