我想知道以下代码是否会关闭地图函数中询问“回调”中的 id 值。
val id = if (model.id.isEmpty) UUID.randomUUID().toString else model.id
val result = couchbaseActor ? SetDoc(s"user:$id", model.toJson.compactPrint)
result map {
case true => sender ! Right(Success(id))
case false => sender ! Left(makeFailureFromErrorEnum(ErrorCode.DbSaveFailed, List("User", "Error occurred while saving to Couchbase")))
}
谢谢,亚伦
最终解决方案:
消息处理程序:
case SaveUserReq(model) => saveDocument[User](sender, "User", model.id, model)
定义:
def saveDocument[T:JsonWriter](requester: ActorRef, prefix: String, id: String, model: T): Unit = {
couchbaseActor ? SetDoc(s"${prefix.toLowerCase}:$id", model.toJson.compactPrint) map {
case true => requester ! Right(Success(id))
case false => requester ! Left(makeFailureFromErrorEnum(ErrorCode.DbSaveFailed, List(prefix, errorCouchbaseSaveFailed)))
}
}
感谢所有提供帮助的人。