Internally, Play Framework is asynchronous from the bottom up. Play handles every request in an asynchronous, non-blocking way.
How to make non blocking requests to PostgreSQL?
Code at the moment
@Singleton
class Application @Inject()(usersRepossitory: UsersRepository,
cc: ControllerComponents) extends AbstractController(cc) {
def index = Action {
Ok(usersRepository.list().map(_.id).mkString(","))
}
}
case class User(id: Long)
@Singleton
class UsersRepository @Inject()(dbapi: DBApi) {
private val db = dbapi.database("default")
val parser: RowParser[User] = Macro.namedParser[User]
def list: List[User] = db.withConnection { implicit connection =>
val result: List[User] = SQL"SELECT id FROM users".as(parser.*)
result
}
}