在Scala和其他编程语言中,可以使用Futures和Await。(在实际代码中,一个常见的替代方案是使用zip+map而非Await)
在JavaScript/Scala中,异步/等待与什么不同?
def b1() = Future { 1 }
def b2() = Future { 2 }
def a() = Future {
Await.result(b1(),Duration.inf) + Await.result(b2(),Duration.inf)
}
在JavaScript/Scala中,异步/等待与什么不同?
async function b1() { return 1 }
async function b2() { return 3 }
async function a() {
return await b1() + await b2()
}