]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.simulation.sequences/scl/Simantics/Sequences.scl
Allow simulation stop handling in Simantics/Sequences
[simantics/platform.git] / bundles / org.simantics.simulation.sequences / scl / Simantics / Sequences.scl
index b2f9ba5fcb99ef1eaaa3ccf32274b64de356f8cf..e84ca61953d53eba37c1eee7a4d7bc0f1efcc9c0 100644 (file)
@@ -5,6 +5,13 @@ effect Action
     "sequenceAction"
     "org.simantics.simulation.sequences.action.ActionContext"
 
+importJava "org.simantics.simulation.sequences.action.StopReason" where
+    data StopReason
+    STOPPED :: StopReason
+    SIMULATION_DID_NOT_START :: StopReason
+    DIVERGED :: StopReason
+    INTERRUPTED :: StopReason
+
 importJava "org.simantics.simulation.sequences.action.ActionContext" where
     data ActionContext
     
@@ -21,6 +28,7 @@ importJava "org.simantics.simulation.sequences.action.ActionContext" where
     scheduleNow :: (() -> <Action,Proc> a) -> <Action> ()
     scheduleNextStep :: (() -> <Action,Proc> a) -> <Action> ()
     scheduleAt :: Double -> (() -> <Action,Proc> a) -> <Action> ()
+    scheduleWhenStopped :: (StopReason -> <Action,Proc> a) -> <Action> ()
     @JavaName stop
     stop_ :: <Action> ()
 
@@ -62,6 +70,10 @@ The sequence `execute action` is an instantious sequence that executes the opera
 execute :: (<Action,Proc> a) -> Sequence a
 execute action = Sequence (\cont -> cont action)
 
+@inline
+executeWhenStopped :: (StopReason -> <Action,Proc> a) -> Sequence ()
+executeWhenStopped handler = execute (scheduleWhenStopped handler)
+
 """
 The sequence `fork seq` is an instantious sequence that creates a new sequence thread behaving like the sequence `seq`.
 """