I am using code like this to publish a message to Pub/Sub using Akka Streams and complete a context Promise with either success or failure depending on the result of the publish.
val promise = Promise[Unit]
Source.single((PublishRequest(Seq(PublishMessage("some-message"))), promise))
.via(GooglePubSub.publishWithContext("some-topic", config.pubSubConfig))
.map { case (messageIds, promise) =>
promise.success(())
}
I am able to resolve the Promise successfully in the case of success, but if publishing fails, how can I then resolve the Promise as a failure?
I can use recover and recoverWith on the graph stage, but the original request nor the promise is available at that point, only the Throwable. I expect a way to grab the promise and fail it at this point.