我正在尝试使用超时功能创建http4s路由。
我在TimeoutSpec中看到了示例,并创建了超时路由here。
当我编译代码时,我得到下面的错误-
[info] Compiling 12 Scala sources to /Users/rajkumar.natarajan/Documents/Coding/OS/ciris-example/target/scala-2.12/classes ...
[error] /Users/rajkumar.natarajan/Documents/Coding/OS/ciris-example/src/main/scala/is/cir/example/application/Http4sApi.scala:38:45: no type parameters for method apply: (http: cats.data.Kleisli[F,A,org.http4s.Response[G]])(implicit F: cats.effect.Concurrent[F], implicit T: cats.effect.Timer[F], implicit W: org.http4s.EntityEncoder[G,String])cats.data.Kleisli[F,A,org.http4s.Response[G]] in object Timeout exist so that it can be applied to arguments (org.http4s.HttpRoutes[cats.effect.IO])
[error] --- because ---
[error] argument expression's type is not compatible with formal parameter type;
[error] found : org.http4s.HttpRoutes[cats.effect.IO]
[error] (which expands to) cats.data.Kleisli[[β$0$]cats.data.OptionT[cats.effect.IO,β$0$],org.http4s.Request[cats.effect.IO],org.http4s.Response[cats.effect.IO]]
[error] required: cats.data.Kleisli[?F,?A,org.http4s.Response[?G]]
[error] case finite: FiniteDuration => (Timeout(finite)(routes)).orNotFound
[error] ^
[error] /Users/rajkumar.natarajan/Documents/Coding/OS/ciris-example/src/main/scala/is/cir/example/application/Http4sApi.scala:38:54: type mismatch;
[error] found : org.http4s.HttpRoutes[cats.effect.IO]
[error] (which expands to) cats.data.Kleisli[[β$0$]cats.data.OptionT[cats.effect.IO,β$0$],org.http4s.Request[cats.effect.IO],org.http4s.Response[cats.effect.IO]]
[error] required: cats.data.Kleisli[F,A,org.http4s.Response[G]]
[error] case finite: FiniteDuration => (Timeout(finite)(routes)).orNotFound
[error] ^
[error] /Users/rajkumar.natarajan/Documents/Coding/OS/ciris-example/src/main/scala/is/cir/example/application/Http4sApi.scala:38:53: Cannot find implicit value for Concurrent[F].
[error] Building this implicit value might depend on having an implicit
[error] s.c.ExecutionContext in scope, a Scheduler, a ContextShift[F]
[error] or some equivalent type.
[error] case finite: FiniteDuration => (Timeout(finite)(routes)).orNotFound
[error] ^
[error] three errors found
[error] (Compile / compileIncremental) Compilation failed
[error] Total time: 17 s, completed Jan 7, 2019 6:51:48 PM
代码中的类型似乎正确,但是前2个错误是由于第3个错误Cannot find implicit value for Concurrent[F]
造成的。
我在here范围内有Concurrent[IO]
,但不确定为什么仍然出现此错误。
我正在使用http4s 19.0版本。其他版本详细信息可以在here中找到。