=str Fix CompletionStage#toCompletableFuture may throw UnsupportedOperationException.
This commit is contained in:
parent
99cc4e794d
commit
e8a1c3f148
1 changed files with 14 additions and 12 deletions
|
|
@ -21,6 +21,7 @@ import pekko.stream.impl.Stages.DefaultAttributes
|
|||
import pekko.stream.stage.{ GraphStage, GraphStageLogic, OutHandler }
|
||||
|
||||
import java.util.Optional
|
||||
import java.util.concurrent.CompletableFuture
|
||||
import java.util.concurrent.CompletionStage
|
||||
import scala.concurrent.Future
|
||||
import scala.util.{ Failure, Success, Try }
|
||||
|
|
@ -123,20 +124,21 @@ import scala.util.{ Failure, Success, Try }
|
|||
}
|
||||
|
||||
def onPull(): Unit = {
|
||||
val future = f.apply(state).toCompletableFuture
|
||||
if (future.isDone && !future.isCompletedExceptionally) {
|
||||
handle(future.getNow(null))
|
||||
} else {
|
||||
future.handle((r, ex) => {
|
||||
if (ex != null) {
|
||||
asyncHandler(Failure(ex))
|
||||
} else {
|
||||
asyncHandler(Success(r))
|
||||
}
|
||||
null
|
||||
})
|
||||
f.apply(state) match {
|
||||
case cf: CompletableFuture[Optional[Pair[S, E]] @unchecked] if cf.isDone && !cf.isCompletedExceptionally =>
|
||||
handle(cf.join())
|
||||
case future =>
|
||||
future.handle((r, ex) => {
|
||||
if (ex != null) {
|
||||
asyncHandler(Failure(ex))
|
||||
} else {
|
||||
asyncHandler(Success(r))
|
||||
}
|
||||
null
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
setHandler(out, this)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue