scalaplayframeworkscala-catsdoobie

How is this app converting from an IOConnection/IO to a future when integrating with Play?


I'm looking at this repo on github that is using both play and doobie.

I want to understand how it is eventually converting from a connectionIO/IO from cats to a Future that the playframework is built around from.

I'm looking at a controller and I can see the userRepo but I don't see where or how it is going to/from futures to 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


Solution

  • Eventually there is a call to unsafeToFuture which

    Evaluates the effect and produces the result in a Future.

    at line UICtrl.scala#L59. These questions are best answered by Goto definition feature of IDE. For example, Metals provides it for all major editors. Often the shortcut is command+click or control+click on the symbol name.

    enter image description here