在下面的代码片段中,我有一个递归函数调用,用于在网络调用失败时促进重试(Amazon SimpleDB偶尔会返回503并需要重试.)
当我尝试编译时,Scala抱怨道recursive method simpledb_update needs result type.
// sends data to SimpleDB. Retries if necessary
def simpledb_update(name: String, metadata: Map[String,String], attempt: Int) = {
try {
db(config("simpledb_db")) += (name, metadata)
} catch {
case e =>
// if it fails, try again up to 5 times
if(attempt < 6)
{
Thread.sleep(500)
simpledb_update(name, metadata, attempt + 1)
} else
AUlog(name + ": SimpleDB Failed")
}
}
Run Code Online (Sandbox Code Playgroud)
为什么递归函数需要这个?我的想法是只返回一个true/false布尔值来满足编译器...以下编译很好.
// sends data to SimpleDB. Retries if necessary
def simpledb_update(name: String, …Run Code Online (Sandbox Code Playgroud) scala ×1