Closed mainej closed 2 years ago
Hi @mainej I will look on it ASAP, I'm just right now over-saturated with other stuff and can't give time for this. Looks interesting
You are right and there are a bug in future impl. I have fixed it locally and it will be released in next version
OK, great! Thanks for digging into this @niwinz ... I'm looking forward to the next release.
should be fixed in the 9.0.462
Thanks @niwinz! I tested 9.0.462 and futures are cancelled as expected. See https://github.com/clojure-lsp/clojure-lsp/pull/1293
The body of a promise created by
p/future
is always run, even if the promise is cancelled withp/cancel!
. This keeps the common thread pool busier than it needs to be.I'm not sure whether this is a bug in
p/future
, or if there's anotherpromesa.core
function that I should be using.To be more concrete, let's look at what happens when you start more futures than can be processed simultaneously in the common thread pool, cancel all of them, then check which ones were actually run.
If you use
p/future
, all of the tasks are run. That is, the following will always return[1, 2, ... max-n]
.This is in contrast to
CompletableFuture/supplyAsync + Supplier/get
, which never runs more tasks than are initially submitted to the pool. That is, the following always returns a vector containing fewer results, usually[1, 2, ... common-parallelism]
, but never more thancommon-parallelism
of then
s.