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:
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');
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.
⁺(see UML Spec. 11-08-06 11.3.10 CallOperationAction/ 11.3.8 CallAction)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With