【发布时间】:2012-08-04 01:39:08
【问题描述】:
在 Scala 中是否有另一种模式来实现成功和失败闭包?
这种约定与 node.js 库通常的做法类似,没有任何问题,但我只是想知道在 Scala 中是否有另一种方法。
例如:
def performAsyncAction(n: BigInt,
success: (BigInt) => Unit,
failure: FunctionTypes.Failure): Unit = {
然后调用函数
performAsyncAction(10,
{(x: BigInt) =>
/* Code... */
},
{(t: Throwable) =>
e.printStackTrace()
})
谢谢
【问题讨论】:
-
您可以为此使用封装在 Future 中的 Either,或者您可以使用 Future 调用并观察它是成功还是失败。
-
两者都是真的糟糕的模式。
标签: scala closures anonymous-function function-parameter