Command execution order

Chris's Avatar

Chris

01 Sep, 2014 03:19 AM

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?

For example:-

eventCommandMap.map(new Event('myEvent')).toCommand(CommandOne);
eventCommandMap.map(new Event('myEvent')).toCommand(CommandTwo);
CommandOne will always be executed before CommandTwo?

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?

  1. Support Staff 1 Posted by Ondina D.F. on 01 Sep, 2014 10:38 AM

    Ondina D.F.'s Avatar

    Hi Chris,

    What have you tried so far that didn't work?

    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?

    Yes, commands will be executed in the order of their mappings.
    See CommandExecutor. executeCommands()

    https://github.com/robotlegs/robotlegs-framework/blob/master/src/ro...

    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?

    Yes, look at CommandExecutor.executeCommand :
    if (mapping.guards.length == 0 || guardsApprove(mapping.guards, _injector))

    https://github.com/robotlegs/robotlegs-framework/blob/master/src/ro...

    Also, look at the tests, for example execution_sequence_is_guard_command_guard_command_with_multiple_mappings() :

    https://github.com/robotlegs/robotlegs-framework/blob/master/test/r...

    If the guards won't approve the execution of CommandOne, CommandTwo will run nevertheless.

    hth
    Ondina

  2. 2 Posted by Chris on 01 Sep, 2014 11:59 AM

    Chris's Avatar

    The problem I'm having is trying to find the implementation of eventCommandMap.map(...) where I can see how things are added to mappings .

    Other than that, it seems to work. I just needed some assurances that it works the way I need it to work.

  3. Support Staff 3 Posted by Ondina D.F. on 01 Sep, 2014 12:24 PM

    Ondina D.F.'s Avatar

    The problem I'm having is trying to find the implementation of eventCommandMap.map(...) where I can see how things are added to mappings

    Do you mean these?
    EventCommandMap->EventCommandTrigger->CommandMapper....

    https://github.com/robotlegs/robotlegs-framework/tree/master/src/ro...

    https://github.com/robotlegs/robotlegs-framework/tree/master/src/ro...

    https://github.com/robotlegs/robotlegs-framework/blob/master/src/ro...

  4. 4 Posted by Chris on 02 Sep, 2014 12:37 AM

    Chris's Avatar

    Ok, I'm convinced the order is what I need it to be (see CommandMappingList.addMapping()`).

    But what scares me is the existence of a CommandMappingList.sortMappings() function call in the CommandMappingList.getList(). Where is this sort function defined and what is the how and why of sorting mappings?

  5. Support Staff 5 Posted by Ondina D.F. on 08 Sep, 2014 12:26 PM

    Ondina D.F.'s Avatar

    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.

  6. Support Staff 6 Posted by creynders on 08 Sep, 2014 01:35 PM

    creynders's Avatar

    Hi Chris,

    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.

    So yes, commands are executed in the same order as they are mapped (in the EventCommandMap).

    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:
    https://github.com/robotlegs/robotlegs-framework/blob/master/src/ro...

    As you can see there's no call to ICommandList#withSortFunction there, which means the lists are without sorting function.

  7. 7 Posted by Chris on 08 Sep, 2014 11:01 PM

    Chris's Avatar

    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).

  8. Support Staff 8 Posted by creynders on 09 Sep, 2014 10:06 AM

    creynders's Avatar

    Sorting of the lists is meant for command map extension creators. For
    instance: you could create a PriorityEventCommandMap, where commands are
    mapped to events but by priority. In such a command map it would be
    necessary to be able to sort the list of commands by priority.

  9. Chris closed this discussion on 09 Oct, 2014 05:06 AM.

Comments are currently closed for this discussion. You can start a new one.

Keyboard shortcuts

Generic

? Show this help
ESC Blurs the current field

Comment Form

r Focus the comment reply box
^ + ↩ Submit the comment

You can use Command ⌘ instead of Control ^ on Mac