Order of execution for commands mapped to the same signal?
I have a very large application that I'm switching over to signals for performance reasons. I'm noticing that the timing of things is not going the way it used to with events. For example, with multiple commands mapped to one event, I will see the commands executed in the order that they are mapped to the event, but with signals, this is not always the case. Here's some code illustrating the situation.
public class MyContext extends Context{
public function MyContext(contextView:DisplayObjectContainer=null){
super(contextView);
}
override public function startup():void{
commandMap.mapEvent(MyEvent.IMPORTANT_EVENT, CommandOne, MyEvent);
commandMap.mapEvent(MyEvent.IMPORTANT_EVENT, CommandTwo, MyEvent);
super.startup();
}
}
I put trace statements in the execute function of each command, and I see the trace from CommandOne then the trace from CommandTwo. Now switching to signals.
public class MyContext extends SignalContext{
public function MyContext(contextView:DisplayObjectContainer=null){
super(contextView);
}
override public function startup():void{
signalCommandMap.mapSignalClass(MyImportantSignal, CommandOne);
signalCommandMap.mapSignalClass(MyImportantSignal, CommandTwo);
super.startup();
}
}
I see the trace from CommandTwo, and my application breaks because CommandOne did not execute first. If I switch the order of the lines:
public class MyContext extends SignalContext{
public function MyContext(contextView:DisplayObjectContainer=null){
super(contextView);
}
override public function startup():void{
signalCommandMap.mapSignalClass(MyImportantSignal, CommandTwo);
signalCommandMap.mapSignalClass(MyImportantSignal, CommandOne);
super.startup();
}
}
Then I see the trace from CommandOne, and then the trace from CommandTwo. This seems unintuitive. Is there a bug here, or does the SignalCommandMap not execute commands in the order they were mapped?
Comments are currently closed for this discussion. You can start a new one.
Support Staff 2 Posted by Ondina D.F. on 20 Mar, 2012 05:20 PM
Hi John,
Sorry for the delay, but your message got stuck in tender’s spam filter for some reason.
Not sure, but I think there were some bugs in older versions.
Please take a look at Neil’s answers from this thread ( sync/async):
http://knowledge.robotlegs.org/discussions/problems/379-sequencing-...
Hope that helps.
Ondina
3 Posted by johnthomascraig on 22 Mar, 2012 04:27 AM
Hi Ondina D.F. Thanks for the response, so it looks like neil mentioned this issue in the post you linked to:
So, do you suppose he's saying that if we want to have the commands mapped to signals called in the order that they're mapped, that we'd have to use signals that extend PrioritySignal and a different version of the SignalCommandMap that used IPrioritySignal? Am I interpreting that correctly? Has anyone put anything like that together to your knowledge? Thanks, John
Support Staff 4 Posted by Ondina D.F. on 22 Mar, 2012 09:04 AM
I'll ask Neil to answer that:)
5 Posted by Stray on 22 Mar, 2012 09:13 AM
Neil will answer better, but as the SCM uses Signals and the PrioritySignal extends Signal, you don't need a new map but you just need your custom Signals to extend PrioritySignal and not just Signal.
Stray
6 Posted by neil on 22 Mar, 2012 09:31 AM
OK, so you are using the version of signals with Joas Fractal Linked list. it dispatches signals in reverse order. to get it to run in the expected order you need to:
1) extend a PrioritySignal - (this adds very little over head to the signal). This will then run in either the order of mapping, or opn the priority passed.
2) use a version with out joas LL.
7 Posted by neil on 22 Mar, 2012 09:41 AM
V0.8 does not have the LL, and that is the version I have been using. I don't have any data on this, but the optimisation in v0.9 may be irrelevant if you are then using PrioritySignals, as the opt run is FIFO
you could look at turbosignals or richardlords
both of which are implemented for opt speeds. of course you'ld have to roll your own SignalCommandMap
hope this all helps
8 Posted by neil on 22 Mar, 2012 09:42 AM
sorry, to answer a previous question, you could use the same SignalCommandMap, as all signals impl ISignal. My choice has been to use v0.08 (as stated)
9 Posted by johnthomascraig on 30 Mar, 2012 04:16 PM
Maybe my git skills are not so good, but I tried checking out V0.8, and in that version there is the IPrioritySignal interface, but no implementation of it? Using the current version, I switched all my signals to use PrioritySignal or extend PrioritySignal, and everything seems to be working as expected. I discovered the override for registerListener in PrioritySignal is where all the magic happens. Thanks everyone for your help!
10 Posted by neil on 30 Mar, 2012 04:22 PM
No Problem John.
You wont find a PrioritySignal implementation in v0.8, only in v0.9
Just to clarify:
Using v0.8 use Signals as usual, and they will execute in expected order.
Using 0.9 Signals execute in reverse order unless you extend PrioritySignal
if you do get a chance to do some speed testing
v0.8 vs v0.9 using PrioritySignal, I'd be interested to hear the results
cheers
Ondina D.F. closed this discussion on 11 Apr, 2012 11:04 AM.