0
我下面这个教程中lagom执行流程 - https://www.lagomframework.com/documentation/1.3.x/scala/ServiceImplementation.html无法理解
我创建了一个记录的维修
//logged takes a ServerServiceCall as argument (serviceCall) and returns a ServerServiceCall.
//ServerServiceCall's compose method creates (composes) another ServerServiceCall
//we are returing the same ServerServiceCall that we received but are logging it using println
def logged[Request,Response](serviceCall:ServerServiceCall[Request,Response]) = {
println("inside logged");
//return new ServerServiceCall after logging request method and uri
ServerServiceCall.compose({
requestHeader=>println(s"Received ${requestHeader.method} ${requestHeader.uri}")
serviceCall
}
)}
我用记录如下:
override def hello3 = logged(ServerServiceCall
{ (requestHeader,request) =>
println("inside ssc")
val incoming:Option[String] = requestHeader.getHeader("user");
val responseHeader = ResponseHeader.Ok.withHeader("status","authenticated")
incoming match {
case Some(s) => Future.successful((responseHeader,("hello3 found "+s)))
case None => Future.successful((responseHeader,"hello3 didn't find user"))
}
})
我预计inside ssc
将首先打印,然后打印在日志中,但它是相反的。不应该首先评估传递给函数的参数吗?
我明白了。为什么?
inside logged Received POST /hello3 inside ssc
想要尝试代码,但它没有编译:( –
仍然在编写代码,但有一些下面的问题(请原谅有限的scala知识) - 1.什么时候hello3被调用?2)Lagom执行打印但它创建actualServiceCall时不执行ServerServiceCall内的代码?为什么?此时仅创建ServerServiceCall的对象吗?当lagom使用其调用函数时,传递给该代码块的代码会被执行吗? 3)编写serviceCall时执行了创建serviceCall时传递给它的代码块吗? –
啊!我的一些疑惑在第一段中解释 - https://www.lagomframework.com/documentation/1.3.x/scala/ServiceImplementation.html。仍然不能编译代码:( –