Skip to content

Commit

Permalink
Merge pull request #2907 from armanbilge/issue/2903
Browse files Browse the repository at this point in the history
Fix `Async#fromCompletableFuture` cancelation
  • Loading branch information
vasilmkd authored Mar 24, 2022
2 parents 8d8f074 + 4ec557d commit 8956adf
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,14 @@ private[kernel] trait AsyncPlatform[F[_]] { this: Async[F] =>
}))
}

Some(void(delay(cf.cancel(false))))
Some(
ifM(delay(cf.cancel(false)))(
unit,
async_[Unit] { cb =>
cf.handle[Unit]((_, _) => cb(Right(())))
()
}
))
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,5 +40,20 @@ class AsyncPlatformSpec extends BaseSpec {
_ <- IO(cf.join() must throwA[CancellationException])
} yield ok
}

"backpressure on CompletableFuture cancelation" in ticked { implicit ticker =>
// a non-cancelable, never-completing CompletableFuture
def cf = new CompletableFuture[Unit] {
override def cancel(mayInterruptIfRunning: Boolean) = false
}

val io = for {
fiber <- IO.fromCompletableFuture(IO(cf)).start
_ <- smallDelay // time for the callback to be set-up
_ <- fiber.cancel
} yield ()

io must nonTerminate
}
}
}

0 comments on commit 8956adf

Please sign in to comment.