Hello, i finally get some code like this:
Directive.Intent[Any, Any] {
case Path(PostSeg(title :: Nil)) => for {
_ <- GET
_ <- Accepts.Json
request <- Directives.request[Any]
postEntry <- Directive((_:HttpRequest[Any]) => postEntry[A](title).run(config))
} yield postEntry.onComplete {
case Success(post) => post.fold[JsonResponse](BlogPostNotFound)(post => BlogSuccess(post.asJson))
case Failure(t) => BlogPostNotFound
}
where:
type ResultM[+A] = Result[ResponseFunction[Any],A]
postEntry[A] returns a Kleisli[ResultM, Config, Future[Option[A]]]
so at the end the postEntry is a Future[Option[PostEntry]].
Obviosly is not working because the onComplete is returning Unit and doesnt fit under the ResponseFunction type expected.
The more obvious way to solve this is to block the execution until the complete is done, but is there any better aproach?
Thanks.