tag:robotlegs.tenderapp.com,2009-10-18:/discussions/questions/2371-chaining-asyc-commandsRobotlegs: Discussion 2018-10-18T16:35:49Ztag:robotlegs.tenderapp.com,2009-10-18:Comment/274993902013-06-26T12:49:59Z2013-06-27T08:04:36ZChaining async commands<div><p>Hi,</p>
<p>I am hoping one of you good people could help me with chaining
async commands in RL1, which need to be executed in order.</p>
<p>I have a series of commands that take advantage of the detain()
and release() methods or RL commands. These are each asynchronous
commands that need to wait for certain activities to complete
before dispatching 'completed' events for other actors to react to.
Generally - I am waiting for services to update remote
Databases.</p>
<p>Now - each of these commands are usable in their own right, and
I'd like to keep them that way. But sometimes I'd like for two or
more async commands to be chained together.</p>
<p>So, the flow works something like this (step 4 is what I'd
really like an answer to):</p>
<ol>
<li>event is dispatched and mapped to ChainCommand. ChainCommand
executes.<br></li>
<li>ChainCommand immediately gets detained.<br></li>
<li>ChainCommand sends event to execute async CommandA<br></li>
<li>When CommandA is released, ChainCommand is (somehow)
informed.<br></li>
<li>ChainCommand then sends an event to execute async
CommandB<br></li>
<li>When CommandB is released, ChainCommand is again
informed.<br></li>
<li>ChainCommand is released.</li>
</ol>
<p>Is this possible? hope this approach makes sense.</p>
<p>Many thanks!</p></div>seansuttontag:robotlegs.tenderapp.com,2009-10-18:Comment/274993902013-06-26T13:02:00Z2013-06-26T13:02:00ZChaining async commands<div><p>Daisy chaining commands gets real messy really fast. I'd
definitely recommend against it.<br>
There's a very handy RL1 utility I use to sequence commands
(synced, asynced or mixed) called macrobot<br>
<a href=
"https://github.com/Aaronius/robotlegs-utilities-Macrobot">https://github.com/Aaronius/robotlegs-utilities-Macrobot</a></p>
<p>Or the other option is to use a statemachine, which is the
cleanest, since it allows you to create far more complex behaviours
influenced by the results of each command:<br>
<a href=
"https://github.com/joelhooks/robotlegs-utilities-StateMachine">https://github.com/joelhooks/robotlegs-utilities-StateMachine</a></p></div>creynderstag:robotlegs.tenderapp.com,2009-10-18:Comment/274993902013-06-26T13:46:52Z2013-06-26T13:46:52ZChaining async commands<div><p>Thanks for your reply creynders :)</p>
<p>I think that with every application I have built with PureMVC or
Robotlegs, I have reached a stage where 'daisy-chaining' some
commands effectively becomes essential for development to continue.
Why do you think this invariably becomes 'messy'?</p>
<p>If - as in my above example - CommandA and CommandB are
functional in their own right, and correctly loosely coupled with
the other actors, why are a few higher level commands out of the
question? The fact that Robotlegs has detain/release and PureMVC
has macro commands implies there's a logic to what I'm saying.</p>
<p>Thank you for the links! I have found the barrier to entry with
the Statemachine design pattern and as3 mvc frameworks very high,
though. I have found very few examples over the years to help with
my own implementation, and it strikes me that a lot of events would
get fired with this pattern that would frequently get ignored, and
present worryingly misleading code.</p>
<p>Procedurally executing and observing controller code is always a
vital part of any project I work on. Async management with as3 is
hard enough and I've always felt RL could make a great difference
here (on top of all the other awesome stuff it already does!).</p>
<p>I really welcome further discussion here while I check out
macrobot!</p>
<p>Thanks again creynders!</p></div>seansuttontag:robotlegs.tenderapp.com,2009-10-18:Comment/274993902013-06-26T14:20:32Z2013-06-26T14:20:32ZChaining async commands<div><p>No, no, having commands executed in some kind of sequence is a
very common<br>
requirement. <em>Daisy chaining</em> commands however is a bad
idea. For instance:<br>
CommandA calls CommandB when finished, CommandB calls CommandC
when<br>
finished etc. will get you in the innermost circle of Hell in no
time.</p>
<p>State machines take a little while getting used to, but they're
very<br>
powerful and once you "get" them you'll be wondering what was so
hard about<br>
them. And also, you'll be using them all the time.<br>
They are very well worth the effort.</p></div>creynderstag:robotlegs.tenderapp.com,2009-10-18:Comment/274993902013-06-26T14:29:46Z2013-06-26T14:29:46ZChaining async commands<div><p>Ah thanks creynders. I see that my use of the word 'chaining'
was pretty misleading in my 1st post in particular. Thank you for
sticking with me.</p>
<p>Do you have any good resources / examples for RL1 statemachine
implementation?</p>
<p>Thanks again!</p></div>seansutton