SIP-22 - Async - Scala Documentation

#1

By: Philipp Haller and Jason Zaugg

This is a proposal to add constructs that simplify asynchronous and concurrent programming in Scala. The main constructs, async and await, are inspired by similar constructs introduced in C# 5.0. The main purpose of async/await is to make it possible to express efficient asynchronous code in a familiar direct style (where suspending operations look as if they were blocking). As a result, non-blocking code using Scala’s futures API [1] can be expressed without using higher-order functions, such as map and flatMap, or low-level callbacks.


This is a companion discussion topic for the original entry at http://docs.scala-lang.org//sips/pending/async.html
#2

If the purpose of the SIP is avoiding nested braces when calling flatMap, then there is a simpler approach:
Modify Scala parser to allow function literal after an infix expression.

{
  asyncOps1() flatMap value1 =>
  asyncOps2(value1) flatMap value2 =>
  asyncOps3(value2) flatMap value3 =>
  asyncOps4(value3)
}

which should be parsed as

{
  asyncOps1() flatMap { value1 =>
  asyncOps2(value1) flatMap { value2 =>
  asyncOps3(value2) flatMap { value3 =>
  asyncOps4(value3)
}}}}

This stye is very common in Haskell.

#3

It is not about nested braces.
While Future monad allows us to make beauty linear sequences, async-await allows us to build computation graph (non-linear, with branching) over futures with lacking of binding details (like flatMap operator).