Dispatched event from command, but what tricks do I need to think of?

ben's Avatar


20 Sep, 2013 12:37 PM

Hi, I'm trying to dispatch an event from a Command, which is listened to by a (stable and already existing) mediator. The thing is, the mediator never receives it.

I looked at http://knowledge.robotlegs.org/discussions/questions/616-dispatch-a... , but it seems I have a bit of magic lines missing to enable it or something? In the command I do this:

eventDispatcher.dispatchEvent( ... );

In the mediator (onRegister) I do this:

eventMap.mapListener( eventDispatcher, ..., doStuff );

But I can't seem to get doStuff to fire?

Any ideas? Tnx, Ben

  1. Support Staff 1 Posted by Ondina D.F. on 20 Sep, 2013 02:25 PM

    Ondina D.F.'s Avatar

    Hi Ben,

    I think of race conditions, i.e. the command dispatches the event before the mediator is able to listen to it.

    But you say that the mediator is already existing.
    So, the question is from where are you triggering the command and when.

    If you're dispatching the event triggering the command from within mediator's onRegister, then you have to make sure you've already added a listener for the event dispatched by the command.

    1. add event listener
    2. dispatch event to trigger the command
    3. dispatch event from command
    4. mediator can react to it

    If that's not the case, I'd need a little more info in order to help you:)


  2. 2 Posted by ben on 20 Sep, 2013 02:43 PM

    ben's Avatar

    Tnx Ondina, let me try to provide whatever I can.

    1. After startup, the app is in stable (idle) condition. The mediator is then alive and through onRegister I make it listen for the RL event.

    2. At a certain moment, the user clicks, which will trigger an asynchronous Command. Not very relevant, but just in case.

    3. After that command is done, a series of events are triggered which fire off other Commands. So command A is executed, which fires an event which will execute Command B, etc..

    4. The event the mediator is listening to, is event B in the sequence above.

    5. The command that is attached to that same event, fires fine.

    6. Other RL events the mediator is attached to, seem to work fine as well.

    Cheers, Ben

  3. 3 Posted by ben on 20 Sep, 2013 02:49 PM

    ben's Avatar

    Argh, just after typing this and trying some random ordering of events, it seems I can get it working if I fire this one first....

    This goes wrong:

    override public function execute():void
      dispatch( "a random other event");
      dispatch( "the event I need" );

    This works:

    override public function execute():void
      dispatch( "the event I need" );
      dispatch( "a random other event");
  4. Support Staff 4 Posted by Ondina D.F. on 20 Sep, 2013 03:21 PM

    Ondina D.F.'s Avatar

    Glad you figured it out.

    You might want to take a look at this utility:

    Macro command utility for Robotlegs which provides the ability to execute batches of commands in sequential and/or parallel fashion


  5. 5 Posted by ben on 20 Sep, 2013 09:25 PM

    ben's Avatar

    Jup, I am using that one. Great stuff. I'm mostly using it for the Async part. The Sequence part looks great, but doesn't add much value for me in this case (not sure in which case it will, only if you need to have an atomic execution of multiple events). But I should read into it more in the future.

    Thanks for your time/help.


    On 20 sep. 2013, at 17:21, Ondina D.F. <[email blocked]> wrote:

  6. Support Staff 6 Posted by Ondina D.F. on 21 Sep, 2013 12:56 PM

    Ondina D.F.'s Avatar

    No problem, Ben:)

  7. Ondina D.F. closed this discussion on 21 Sep, 2013 12:56 PM.

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

Keyboard shortcuts


? 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