我试图弄清楚如何用SCXML编码子程序。作为soub例程,我指的是可以从不同的进程(状态)调用并返回给调用者的进程/例程/函数。
起初,我尝试使用历史状态,但返回时调用者状态将重新启动,因此进入循环。这就是素描。
<scxml>
<final id="Final">
<onexit>
<transition target="ProcA" />
<transition target="ProcB" />
</onexit>
</final>
<state id="Sub">
<transition target="History" />
</state>
<state>
<history id="History" />
<final id="ProcA">
<onexit>
<transition target="Sub" />
</onexit>
</final>
<final id="ProcB">
<onexit>
<transition target="Sub" />
</onexit>
</final>
</state>
</scxml>发布于 2020-05-23 16:26:19
简单地说,就是使用SCXML的invoke标记,它允许解释器生成一个新的SCXML会话。Invoke还可以通过type属性进行扩展,因此如果解释器支持它,它可以生成其他类型的子进程。调用的语义要求父会话在启动被调用会话的状态中等待,直到被调用的会话达到最终状态。您可以在下面看到一个简短的示例,其中使用SCXML的send标记并行调用两个会话并相互通信:
https://jsbin.com/hegiyuk/edit?output
<scxml
datamodel="ecmascript"
xmlns="http://www.w3.org/2005/07/scxml"
version="1.0">
<parallel id="p">
<state id="1">
<invoke id="session_1">
<content>
<scxml
datamodel="ecmascript"
xmlns="http://www.w3.org/2005/07/scxml"
version="1.0">
<state id="session-1-foo">
<onentry>
<log label="here1"/>
<send event="ping-from-1" delay="2s" target="#_session_2"/>
</onentry>
<transition event="ping-from-2" target="session-1-bar"/>
</state>
<state id="session-1-bar">
<onentry>
<log label="here3"/>
<send event="pong-from-1" delay="2s" target="#_session_2"/>
</onentry>
<transition event="pong-from-2" target="session-1-foo"/>
</state>
</scxml>
</content>
</invoke>
</state>
<state id="2">
<invoke id="session_2">
<content>
<scxml
datamodel="ecmascript"
xmlns="http://www.w3.org/2005/07/scxml"
version="1.0">
<state id="session-2-foo">
<onentry>
<log label="here2"/>
<send event="ping-from-2" delay="2s" target="#_session_1"/>
</onentry>
<transition event="ping-from-1" target="session-2-bar"/>
</state>
<state id="session-2-bar">
<onentry>
<log label="here4"/>
<send event="pong-from-2" delay="2s" target="#_session_1"/>
</onentry>
<transition event="pong-from-1" target="session-2-foo"/>
</state>
</scxml>
</content>
</invoke>
</state>
</parallel>
</scxml>https://stackoverflow.com/questions/61971407
复制相似问题