我试图结合Playframework与猫的效果3无标签的最终风格。
我被困在了向未来的转变上。Play的动作只需要价值或未来,我想要达到的,异步处理。
def method = authed { _ =>
val program: EitherT[IO, Throwable, Int] = ???
program
}
def authed[F[_]: Async](fa: Request => F[Result]): Action = {
???
}在猫效应2,这是可能的通过_.toIO.unsafeToFuture,但现在它改变了。根据文档,我必须使用调度程序。找到了最初的想法论吉乌布,但是一个新的签名是F[Future[A]]
def beforeF[F[_]: Effect, A](fa: F[A]): Future[A] = fa.ioIO.unsafeToFuture()
// Note: Using a `Dispatcher` resource is cheap - don't worry about it
def preferredAfterF[F[_]: Async, A](fa: F[A]): F[Future[A]] = Dispatcher[F].use(_.unsafeToFuture(fa))有人成功了吗?
发布于 2022-06-15 12:18:14
构造您的路由,以便它们可以作为依赖项访问Disptacher对象,那么生命周期将是合适的。
class MyRoute[F[_]: MonadThrow](disp: Dispatcher[F]) {
def method = authed { _ =>
val program: EitherT[IO, Throwable, Int] = ???
disp.unsafeToFuture(program.value)
}
}(这可能需要对allocated和IORuntime的unsafeRunSync在Dispatcher[IO]资源上进行一些修改,这取决于应用程序的连接方式)
https://stackoverflow.com/questions/72127799
复制相似问题