Action
is niet ontworpen om met futures te werken. Gebruik Action.async
, die zal "wachten" (technisch gezien niet wachten, maar plannen) tot de toekomst klaar is:
def rect(swLon: Float, swLat: Float, neLon: Float, neLat: Float) = Action.async {
val sb = new StringBuilder()
sb.append("<tt>boundingBox: swLon=" + swLon + ", swLat=" + swLat + ", neLon=" + neLon + ", neLat=" + neLat + "</tt>")
if (oDb.isDefined) {
val collection: MongoCollection[Document] = oDb.get.getCollection(collectionName)
val fut = getFutureOne(collection) // returns a Future[Seq[Document]]
fut.map {docs =>
setMongoJson(doc.toJson)
Ok(sb.toString)
} recover {
case e => BadRequest("FAIL: " + e.getMessage)
}
} else Future.successful(Ok("Not defined"))
}
Bekijk dit ter referentie:https://www.playframework.com/documentation /2.4.x/ScalaAsync