pjfanning / pekko-http-json

Integrate some of the best JSON libs in Scala with Pekko HTTP
Apache License 2.0
25 stars 1 forks source link

investigate use of `Future.fromTry` #19

Open pjfanning opened 3 months ago

pjfanning commented 3 months ago

There are implicit defs that do things like

  implicit def fromByteStringUnmarshaller[A: JavaTypeable](implicit
      objectMapper: ObjectMapper with ClassTagExtensions = defaultObjectMapper
  ): Unmarshaller[ByteString, A] =
    Unmarshaller { _ => bs =>
      Future.fromTry(Try(objectMapper.readValue[A](ByteStringInputStream(bs))))
    }

It seems more correct to have standard Future like:

    Unmarshaller { ec => bs =>
      Future(objectMapper.readValue[A](ByteStringInputStream(bs))(ec)
    }
pjfanning commented 3 months ago

@gabfssilva You wrote this streaming code for akka-http-json. I have forked it for Apache Pekko usage. Feel free to ignore this but if you have time, could I ask whether there is a good reason to use Future.fromTry instead of running a Future on an ExecutionContext instead? The latter feels like a more correct approach to dealing with the async code.