首页 > 解决方案 > 与 Play 集成时,此应用程序如何从 IOConnection/IO 转换为未来?

问题描述

我正在 github 上查看这个同时使用 play 和 doobie 的 repo。

我想了解它最终是如何从猫的 connectionIO/IO 转换为构建 playframework 的 Future 的。

我正在查看一个控制器,我可以看到 userRepo,但我看不到它从期货到 IO 的去向或方式。

  def doEdit(): Action[AnyContent] = UserAction { implicit req =>
    GsForms.user.bindFromRequest.fold(
      formWithErrors => editView(formWithErrors),
      data => userRepo.edit(data)
        .map(_ => Redirect(PublishedSpeakerRoutes.detail(req.user.slug)).flashing("success" -> "Profile updated"))
    )

}

https://github.com/gospeak-io/gospeak/blob/36fd9dd4ebe314c2ca8e02e2e2c714b6d399d045/web/app/gospeak/web/pages/user/profile/ProfileCtrl.scala#L28

标签: scalaplayframeworkscala-catsdoobie

解决方案


unsafeToFuture最终会有一个呼叫

评估效果并在 Future 中产生结果。

UICtrl.scala#L59行。这些问题最好通过IDE的Goto 定义功能来回答。例如,Metals 为所有主要编辑提供它。通常快捷方式是符号名称command+clickcontrol+click符号名称。

在此处输入图像描述


推荐阅读