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