tag:robotlegs.tenderapp.com,2009-10-18:/discussions/robotlegs-2/11707-command-execution-orderRobotlegs: Discussion 2014-10-09T05:06:26Ztag:robotlegs.tenderapp.com,2009-10-18:Comment/344036062014-09-01T10:38:24Z2014-09-01T10:38:24ZCommand execution order<div><p>Hi Chris,</p>
<p>What have you tried so far that didn't work?</p>
<blockquote>
<p>If an event triggers the execution of 2 distinct commands, Is
the order in which those commands are executed guaranteed to be the
same based on the order in which they are configured?</p>
</blockquote>
<p>Yes, commands will be executed in the order of their
mappings.<br>
See CommandExecutor. executeCommands()</p>
<p><a href=
"https://github.com/robotlegs/robotlegs-framework/blob/master/src/robotlegs/bender/extensions/commandCenter/impl/CommandExecutor.as#L60">
https://github.com/robotlegs/robotlegs-framework/blob/master/src/ro...</a></p>
<blockquote>
<p>And if CommandOne has a guard on it and the guard prevents
CommandOne from executing, the evaluation of the guard will happen
before CommandTwo is executed?</p>
</blockquote>
<p>Yes, look at CommandExecutor.executeCommand :<br>
if (mapping.guards.length == 0 || guardsApprove(mapping.guards,
_injector))</p>
<p><a href=
"https://github.com/robotlegs/robotlegs-framework/blob/master/src/robotlegs/bender/extensions/commandCenter/impl/CommandExecutor.as#L80">
https://github.com/robotlegs/robotlegs-framework/blob/master/src/ro...</a></p>
<p>Also, look at the tests, for example
execution_sequence_is_guard_command_guard_command_with_multiple_mappings()
:</p>
<p><a href=
"https://github.com/robotlegs/robotlegs-framework/blob/master/test/robotlegs/bender/extensions/commandCenter/impl/CommandExecutorTest.as#L155">
https://github.com/robotlegs/robotlegs-framework/blob/master/test/r...</a></p>
<p>If the guards won't approve the execution of CommandOne,
CommandTwo will run nevertheless.</p>
<p>hth<br>
Ondina</p></div>Ondina D.F.tag:robotlegs.tenderapp.com,2009-10-18:Comment/344036062014-09-01T11:59:41Z2014-09-01T11:59:41ZCommand execution order<div><p>The problem I'm having is trying to find the implementation of
<code>eventCommandMap.map(...)</code> where I can see how things
are added to <code>mappings</code> .</p>
<p>Other than that, it seems to work. I just needed some assurances
that it works the way I need it to work.</p></div>Christag:robotlegs.tenderapp.com,2009-10-18:Comment/344036062014-09-01T12:24:46Z2014-09-01T12:24:46ZCommand execution order<div><blockquote>
<p>The problem I'm having is trying to find the implementation of
eventCommandMap.map(...) where I can see how things are added to
mappings</p>
</blockquote>
<p>Do you mean these?<br>
EventCommandMap->EventCommandTrigger->CommandMapper....</p>
<p><a href=
"https://github.com/robotlegs/robotlegs-framework/tree/master/src/robotlegs/bender/extensions/eventCommandMap">
https://github.com/robotlegs/robotlegs-framework/tree/master/src/ro...</a></p>
<p><a href=
"https://github.com/robotlegs/robotlegs-framework/tree/master/src/robotlegs/bender/extensions/eventCommandMap/impl">
https://github.com/robotlegs/robotlegs-framework/tree/master/src/ro...</a></p>
<p><a href=
"https://github.com/robotlegs/robotlegs-framework/blob/master/src/robotlegs/bender/extensions/commandCenter/impl/CommandMapper.as">
https://github.com/robotlegs/robotlegs-framework/blob/master/src/ro...</a></p></div>Ondina D.F.tag:robotlegs.tenderapp.com,2009-10-18:Comment/344036062014-09-02T00:37:41Z2014-09-02T00:37:41ZCommand execution order<div><p>Ok, I'm convinced the order is what I need it to be (see
CommandMappingList.addMapping()`).</p>
<p>But what scares me is the existence of a
<code>CommandMappingList.sortMappings()</code> function call in the
<code>CommandMappingList.getList()</code>. Where is this sort
function defined and what is the how and why of sorting
mappings?</p></div>Christag:robotlegs.tenderapp.com,2009-10-18:Comment/344036062014-09-08T12:26:40Z2014-09-08T12:26:40ZCommand execution order<div><p>I hoped, and am still hoping, that creynders would respond to
your last questions, since he is the one who last authored the
command extensions and knows what everything means and is supposed
to do.</p></div>Ondina D.F.tag:robotlegs.tenderapp.com,2009-10-18:Comment/344036062014-09-08T13:35:30Z2014-09-08T13:35:30ZCommand execution order<div><p>Hi Chris,</p>
<p>The sort function is only executed if the list is configured to
have a sorting function, which is not the case for the
EventCommandMap. This is built in however, since some other command
maps do need sorting.</p>
<p>So yes, commands <em>are</em> executed in the same order as they
are mapped (in the EventCommandMap).</p>
<p>For each event a trigger is created which maintains its list of
commands that need to be executed when the event is called. The
instantiation of the list happens here:<br>
<a href=
"https://github.com/robotlegs/robotlegs-framework/blob/master/src/robotlegs/bender/extensions/eventCommandMap/impl/EventCommandTrigger.as#L60">
https://github.com/robotlegs/robotlegs-framework/blob/master/src/ro...</a></p>
<p>As you can see there's no call to
<code>ICommandList#withSortFunction</code> there, which means the
lists are without sorting function.</p></div>creynderstag:robotlegs.tenderapp.com,2009-10-18:Comment/344036062014-09-08T23:01:53Z2014-09-08T23:01:53ZCommand execution order<div><p>Thanks for that. Although you haven't answered the part about
the how and why of sorting. Normally, I would look at the asdocs to
give me a clue as to how to write the sorting function and then I
would understand why I would need to sort, but the asdocs are
incomplete (see issue #167).</p></div>Christag:robotlegs.tenderapp.com,2009-10-18:Comment/344036062014-09-09T10:06:58Z2014-09-09T10:06:58ZCommand execution order<div><p>Sorting of the lists is meant for command map extension
creators. For<br>
instance: you could create a PriorityEventCommandMap, where
commands are<br>
mapped to events but by priority. In such a command map it would
be<br>
necessary to be able to sort the list of commands by priority.</p></div>creynders