declex icon indicating copy to clipboard operation
declex copied to clipboard

Action support for Functions

Open smaugho opened this issue 7 years ago • 0 comments

When a method returns a value in java, right now it is not possible to use Actions when the result is inside an action. The biggest issue with it, it's that the result of the action could be undefined if it is returned inside an action itself.

To handle this situation the framework can detect if the "return" statement is inside an Action or not. When this is detected, actionWithResult (the method) will be used as an action itself whose result can be returned at any moment in the future. When actionWithResult is invoked, then it follows the same rules than actions (cannot be used in "private" or "static" calls, or in some specific places).

Now, if the user calls actionWithResult without using the result, nothing would change apparently, but if the user requires the result, then whole the action mechanism for that method will be triggered:


void someMethod() {
    int result = actionWithResult();
   //Do something with result 
}

int actionWithResult() {
    $SomeAction();
    //Do operations;
    return someResultVariable;
}
 

Note that in the above case the code in //Do something with result will be triggered only after $SomeAction() in the method actionWithResult be concluded and the result "someResultVariable" be returned.

smaugho avatar Mar 19 '17 16:03 smaugho