Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Asynchronous Callbacks in UML Activity Diagrams

I'm trying to model my Application with UML Activity Diagrams. I'm using JavaScript and Node.js and lots of asynchronous callbacks. Here is what I came up with:

Activity Diagram

What do you think? Do you understand whats going on? I'm using a "generic connector" to associate the callback with the action ("run MyClass.myMethod) and a fork-node to show the "parallel" execution. I did not find a written word about callbacks in Activity Diagrams anywhere on the web or my books.

EDIT This would be the JavaScript code for the diagram:

var MyClass = function () {
    //constructor
};
MyClass.prototype = {
    myMethod : function(cb) {
        //this is an async method
        var result = 5 + 5;
        setTimeout(function () {
            cb(null, result);
        },100); //execute Callback after 100ms
    }
};

//instanciate a MyClass Object
var myClassInstance = new MyClass();

//create a callback function that prints the result
var callbackFunction = function (err,result) {
    console.log(result);
};

myClassInstance.myMethod(callbackFunction);
console.log('I am first');
like image 633
Chris Avatar asked Jul 11 '12 13:07

Chris


1 Answers

A correct way to show callbacks is the following:⁺

You instanciate a Object, pass it to the target-port and call the specified operation (calculateTime) on it. The control flow continues immediately and when the asynchronous operation finishes, the result is transfered to the result-pin. Arguments for the async call can be specified by adding more object-(in)put pins to the Action.

async callback Activity Diagram

⁺(see UML Spec. 11-08-06 11.3.10 CallOperationAction/ 11.3.8 CallAction)

like image 179
Chris Avatar answered Sep 19 '22 05:09

Chris