1

Many modern languages promote asynchronous calls, with a way to wait for the result when it's really needed. Example: async/await in C# and Swift or promise/future in C++. Take the following hypothetical implementation :

class X { 
  private Y y; 
  public async void doSomething() {
    var someTask = y.doSomeAsyncOp();// Asynchronous call 
    doSomethingImmediately();        // Potentially in parallel with async behavior
    var result = await someTask;     // Getting or waiting for result of async call
  }
  ...
}

This implements the intent of a reply for the async call in the design:

sequence diagram with async call and async reply

Unfortunately, according to the UML 2.5.1, reply messages seem to be meant only for synchronous calls and asynchronous calls are not supposed to have replies. See section 17.4.3:

If the messageSort is reply, then the Message represents the return from a synchronous call to the Operation. The arguments of the Message correspond to the out, inout and return ownedParameters of the Operation (...).

Section 13 of the specifications, which defines synchronous and asynchronous behavior, is consistent with this understanding. So, how to model the design with legit UML?

  • asynchronous message in the opposite direction: would work very well if there would be some callback operation. But in absence of callback, what would be the signature of the message?

  • model the await with a second, synchronous invocation to the end of y's execution specification. Pro: it materialises the synchronisation. But what would be the message signature?

  • intermediate Task lifeline would not be a relevant solution: the very detailed implementation level UML diagram would then be harder to understand than the code. And it doesn't convey well the design intent.

Christophe
  • 68,716
  • 7
  • 72
  • 138
  • The reply can be an (a)synch message back, simply spoken. – qwerty_so Jul 01 '23 at 15:48
  • @qwerty_so yes, but if I'd have several different async and I'd need to be able to identify to which one is the message back meant (e.g. see swift link in the question and search the example with "async let")? I mean for the reply, there's a notation to disambiguate. How'd you do for the message back (except labelling the arrow in plaintext) – Christophe Jul 01 '23 at 17:58
  • Well, just so. A note link between to and fro. In reality the return appears at the `await` clause. So you have some outside messages towards that. You may call the message `await`, can't you? – qwerty_so Jul 01 '23 at 19:59
  • 1
    You might start a bounty. But the fact that there's no other response makes me think that only blind passengers will hop on :-/ – qwerty_so Jul 04 '23 at 21:21

1 Answers1

1

Even though the async/await pattern is used for asynchroneous communication, both the call to the operation and the await have return values and the sender has to wait for them. Therefore, I would suggest to use synchroneous calls.

example sequence diagram

The connection between the two messages is the assignment target someTask of the first operation used as the argument of the await.

Axel Scheithauer
  • 2,758
  • 5
  • 13