<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	xmlns:series="http://unfoldingneurons.com/"
	>

<channel>
	<title>AaronHardy.com &#187; service calls</title>
	<atom:link href="http://aaronhardy.com/tag/service-calls/feed/" rel="self" type="application/rss+xml" />
	<link>http://aaronhardy.com</link>
	<description>For all your Aaron Hardy needs.</description>
	<lastBuildDate>Fri, 20 Apr 2012 14:53:33 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Nimbus &#8211; Macro Commands</title>
		<link>http://aaronhardy.com/flex/nimbus-macro-commands/</link>
		<comments>http://aaronhardy.com/flex/nimbus-macro-commands/#comments</comments>
		<pubDate>Thu, 30 Apr 2009 01:53:17 +0000</pubDate>
		<dc:creator>Aaron Hardy</dc:creator>
				<category><![CDATA[Flex]]></category>
		<category><![CDATA[complex commands]]></category>
		<category><![CDATA[macro commands]]></category>
		<category><![CDATA[mvc]]></category>
		<category><![CDATA[nimbus]]></category>
		<category><![CDATA[parallel command]]></category>
		<category><![CDATA[sequence command]]></category>
		<category><![CDATA[service calls]]></category>

		<guid isPermaLink="false">http://aaronhardy.com/?p=228</guid>
		<description><![CDATA[UPDATE: Since the writing of this post, I&#8217;ve converted to and fully endorse Robotlegs as my MVC framework of choice. I invite you to check it out. I have likewise since converted the concept of macro commands to Robotlegs in a extension called Macrobot. In my recent intro to Nimbus, I mentioned that one of [...]]]></description>
			<content:encoded><![CDATA[<hr/>
<b>UPDATE: Since the writing of this post, I&#8217;ve converted to and fully endorse Robotlegs as my MVC framework of choice. I invite you to <a href="http://www.robotlegs.org" target="_blank">check it out</a>.  I have likewise since converted the concept of macro commands to Robotlegs in a extension called <a href="https://github.com/Aaronius/robotlegs-utilities-Macrobot" target="_blank">Macrobot</a>.</b></p>
<hr/>
<p>In my recent <a href="/flex/nimbus-mvc-framework-intro/">intro to Nimbus</a>, I mentioned that one of the features of Nimbus is macro commands.  In complex applications, macro commands can be a huge time saver and allow you to have a lot of control over handling a group of service calls with minimal code.</p>
<p>Two types of macro commands exist.  The first is a SequenceCommand.  This means its subcommands will be executed sequentially.  In other words, the second subcommand won&#8217;t begin executing until the first subcommand has finished executing.  The SequenceCommand won&#8217;t be considered complete until the last subcommand has finished executing.</p>
<p>The other type of macro command is a ParallelCommand.  As you may have guessed, this means its subcommands will be executed in parallel.  In other words, the first command and second command will execute at the same time.  The ParallelCommand won&#8217;t be considered complete until all subcommands have finished executing.</p>
<p>Just as the synergy of the <a href="http://en.wikipedia.org/wiki/Planeteer" target="_blank">Planeteers</a> can work miracles, so can the synergy of the SequenceCommand and ParallelCommand.  Nesting macro commands can give some enhanced control as we&#8217;ll see here:<span id="more-228"></span></p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;">package controller
<span style="color: #66cc66;">&#123;</span>
	<span style="color: #0066CC;">import</span> nimbus.<span style="color: #006600;">commands</span>.<span style="color: #006600;">ParallelCommand</span>;
	<span style="color: #0066CC;">import</span> nimbus.<span style="color: #006600;">commands</span>.<span style="color: #006600;">SequenceCommand</span>;
&nbsp;
	<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">class</span> MyMacroCommand <span style="color: #0066CC;">extends</span> SequenceCommand
	<span style="color: #66cc66;">&#123;</span>
		<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> MyMacroCommand<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>
		<span style="color: #66cc66;">&#123;</span>
			<span style="color: #0066CC;">this</span>.<span style="color: #006600;">subcommands</span> = <span style="color: #66cc66;">&#91;</span>
					<span style="color: #000000; font-weight: bold;">new</span> CommandA<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>,
					<span style="color: #000000; font-weight: bold;">new</span> ParallelCommand<span style="color: #66cc66;">&#40;</span>
							<span style="color: #66cc66;">&#91;</span>
							<span style="color: #000000; font-weight: bold;">new</span> CommandB<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>,
							<span style="color: #000000; font-weight: bold;">new</span> CommandC<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>
							<span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#41;</span>,
					<span style="color: #000000; font-weight: bold;">new</span> CommandD<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>,
					<span style="color: #000000; font-weight: bold;">new</span> ParallelCommand<span style="color: #66cc66;">&#40;</span>
							<span style="color: #66cc66;">&#91;</span>
							<span style="color: #000000; font-weight: bold;">new</span> CommandE<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>,
							<span style="color: #000000; font-weight: bold;">new</span> SequenceCommand<span style="color: #66cc66;">&#40;</span>
									<span style="color: #66cc66;">&#91;</span>
									<span style="color: #000000; font-weight: bold;">new</span> CommandF<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>,
									<span style="color: #000000; font-weight: bold;">new</span> CommandG<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>
									<span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#41;</span>,
							<span style="color: #000000; font-weight: bold;">new</span> CommandH<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>,
							<span style="color: #000000; font-weight: bold;">new</span> CommandI<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>
							<span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#41;</span>,
					<span style="color: #000000; font-weight: bold;">new</span> CommandJ<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>
					<span style="color: #66cc66;">&#93;</span>;
		<span style="color: #66cc66;">&#125;</span>
	<span style="color: #66cc66;">&#125;</span>
<span style="color: #66cc66;">&#125;</span></pre></div></div>

<p>It&#8217;s probably easier to see what&#8217;s going on just by looking at the code, but here it is in narrative form:</p>
<p>CommandA executes. CommandA completes.  CommandB and CommandC execute.  Both of them complete in whatever order.  CommandD executes. CommandD completes. CommandE, CommandH, and CommandI execute.  While they&#8217;re executing, CommandF executes, CommandF completes, CommandG executes, and CommandG completes.  After CommandE, CommandH, CommandI, CommandF, and commandG all complete, CommandJ executes and then completes.</p>
<p>Note that these subcommands could also be macro commands of their own.  For example, CommandH could be extending ParallelCommand and executing several subcommands within itself.  Macro commands can be a very powerful tool when managing the order and timing of your application&#8217;s processes.  Bon appetit!</p>
]]></content:encoded>
			<wfw:commentRss>http://aaronhardy.com/flex/nimbus-macro-commands/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

