wolfboys commented on code in PR #2243:
URL:
https://github.com/apache/incubator-streampark/pull/2243#discussion_r1065363850
##########
streampark-common/src/main/scala/org/apache/streampark/common/util/CompletableFutureUtils.scala:
##########
@@ -75,36 +80,47 @@ object CompletableFutureUtils {
unit: TimeUnit,
handle: Consumer[T],
exceptionally: Consumer[Throwable]): CompletableFuture[Unit] = {
- future.applyToEither(
+
+ val unitFuture = future.applyToEither(
setTimeout(timeout, unit),
- new JavaFunc[T, Unit] {
+ new JavaFunc[T, Unit]() {
override def apply(t: T): Unit = {
if (handle != null) {
handle.accept(t)
}
}
- }).exceptionally(new JavaFunc[Throwable, Unit] {
+ }).exceptionally(new JavaFunc[Throwable, Unit]() {
override def apply(t: Throwable): Unit = {
if (exceptionally != null) {
exceptionally.accept(t)
}
}
})
+ cancelUnitFuture(unitFuture)
}
def runTimeout[T](future: CompletableFuture[T], timeout: Long, unit:
TimeUnit): CompletableFuture[Unit] = {
- runTimeout(
+ val unitFuture = runTimeout(
future,
timeout,
unit,
null,
- new Consumer[Throwable] {
+ new Consumer[Throwable]() {
override def accept(t: Throwable): Unit = {
if (!future.isDone) {
future.cancel(true)
}
}
})
+ cancelUnitFuture(unitFuture)
+ }
+
+ private[this] def cancelUnitFuture(future: CompletableFuture[Unit]):
CompletableFuture[Unit] = {
+ future.whenComplete(new BiConsumer[Unit, Throwable]() {
+ override def accept(t: Unit, u: Throwable): Unit = {
+ future.cancel(true)
Review Comment:
> Check `!future.isDone` first.
In fact, this judgment is not needed, future.cancel can be executed multiple
times, and the judgment is made in the internal implementation.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]