I'm thinking about how to make subcontexts pass a message back to the parent context, especially when the subcontext is asynchronous and/or long-lived. Here are some options, in a RoleMethod:
1. Return a deferred object from the Interaction
new SubContext().execute().done(self.doSomething).fail(...);
Quite simple, and error handling is the responsibility of the current Context. Very similar is
2. Pass a callback to the subcontext
new SubContext(self.doSomething).execute()
Error handling is now elsewhere. But my issue with 1 and 2: Is it true to DCI passing a function, instead of an object that will play a role? This leads me to
3. Pass the current Role or another object to the Context, letting it play a Role
new SubContext(self).execute()
Here I'm unsure how to pass the message back however. The RoleMethods on self are gone when entering a new Context, so I cannot expose any of them as a RoleInterface. Is this a place for a new Interaction?
4. Create a new Interaction and pass the Context itself, letting it play a Role
new SubContext(context).execute() // context.nextStep() will be called inside the subcontext
What bothers me in this case is that a Role is allowed to pass its Context to another Context. Should it even care about the Context itself, not just the properties of it? And adding an Interaction to the Context for every subcontext, could it be a smell? Or is this a valid point for an Interaction? I'd appreciate your thoughts.
/Andreas