CompletionStage callbacks can prefer dispatcher over common ForkJoinPool#4
Draft
leviramsey wants to merge 10 commits intomainfrom
Draft
CompletionStage callbacks can prefer dispatcher over common ForkJoinPool#4leviramsey wants to merge 10 commits intomainfrom
leviramsey wants to merge 10 commits intomainfrom
Conversation
JustinPihony
reviewed
Mar 6, 2026
| import scala.annotation.nowarn | ||
| import scala.jdk.DurationConverters._ | ||
| import scala.jdk.FutureConverters._ | ||
| //import scala.jdk.FutureConverters._ |
| import akka.pattern.PromiseActorRef | ||
| import akka.pattern.StatusReply | ||
| import akka.util.{ ByteString, Timeout } | ||
| import akka.util.ByteString |
There was a problem hiding this comment.
These can be combined - likely would be via sbt formatting
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The Scala standard library's conversion from Scala future to Java CompletionStage defines the "non-
Async" versions to effectively call theAsyncversion with the Java commonForkJoinPoolspecified. This subtly conflicts with the common understanding of the difference between the non-Asyncversion, and theAsyncversion, as evidenced by various AI answers:Copilot
Gemini
The parasitic behavior of the non-
Asyncversion is not desirable for the futures returned by Akka (consider that the future returned from asking a remote actor would be completed on the remoting dispatcher!), but there's not a great reason to use the common FJP in an Akka application: the default dispatcher provides an FJP which is well-suited to short CPU-bound tasks (including with better observability).This adapts the Scala standard library's conversion to one where the executor to prefer is specified at the time of conversion. CompletionStage-returning calls where it's practical to shift onto the default dispatcher are then adapted to use this:
EntityRefs in typed cluster sharding