summaryrefslogtreecommitdiffstats
path: root/test/uscxml/test-postpone-element.scxml
blob: 185f36735b9af62f6f3f23840596d8f94e30b62a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
<scxml datamodel="ecmascript" name="postpone">
	<script src="http://uscxml.tk.informatik.tu-darmstadt.de/scripts/dump.js" />
	<script>
		var blocked = true;
	</script>
	<state id="idle">

		<!-- request will be postponed until someone unblocks -->
		<transition event="http" target="idle" cond="_event.data.pathComponent[1] == 'block'">
			<if cond="blocked">
				<log expr="'Postponing'" />
				<postpone until="blocked == false;" />
				<else>
					<response status="200" requestexpr="_event.origin">
						<content expr="blocked" />
					</response>
				</else>
			</if>
		</transition>
		
		<!-- unblock - this triggers all postponed events -->
		<transition event="http" target="idle" cond="_event.data.pathComponent[1] == 'unblock'">
			<log expr="'Unblocking'" />
			<script>blocked = false;</script>
			<response status="200" requestexpr="_event.origin">
				<content expr="blocked" />
			</response>
		</transition>
		
		<!-- default -->
		<transition event="http" target="idle" cond="
			_event.data.pathComponent[1] != 'unblock' &amp;&amp; 
			_event.data.pathComponent[1] != 'block'
		">
			<script>dump(_event);</script>
			<response status="200" requestexpr="_event.origin" />
		</transition>

	</state>
	<state id="final" final="true" />
</scxml>