Issue
How to create a Flow.Subscriber in Kotlin?
val body = this.bodyPublisher().map { p -> {
val bs = HttpResponse.BodySubscribers.ofString(StandardCharsets.UTF_8)
val fs = StringSubscriber(bs)
p.subscribe(fs)
bs.body.toCompletableFuture().join()
} }.get()
It returns an empty string
Solution
this.bodyPublisher().map { p -> {
val bs = HttpResponse.BodySubscribers.ofString(StandardCharsets.UTF_8)
val fs = StringSubscriber(bs)
p.subscribe(fs)
bs.body.toCompletableFuture().join()
} }
Using curly braces inside a lambda would return a lambda. It is should be updated as follows
this.bodyPublisher().map { p ->
val bs = HttpResponse.BodySubscribers.ofString(StandardCharsets.UTF_8)
val fs = StringSubscriber(bs)
p.subscribe(fs)
bs.body.toCompletableFuture().join()
}
Answered By - sidgate
Answer Checked By - David Goodson (JavaFixing Volunteer)