Futures

In the procedural cases, all functions are synchron, they return their result directly. In the futures cases, all functions return futures/promises.

Description Procedural Futures
Normal code with exception handling
try {
  auto v = f1();
  return f2(v);
} catch (Exception e) {
  return f3();
}
return f1()
  .thenCompose(v => f2(v))
  .catchException(f3())
Nesting
return f1(f2(f3()));
f3()
  .then(v => f2(v))
  .then(v => f1(v))
Nested ifs
if (f1()) {
  return f2();
} else if (f3()) {
  return f4();
} else {
  return f5();
}
f1().thenCompose(v =>
    if (v) {
      return f2();
    } else {
      return f3()
        .thenCompose(v =>
           if (v) {
             return f4();
           } else {
             return f5();
           }
         };
    }