This is driving me slightly nuts. Inside an actor, I’m doing an HTTP call via Play’s WS library, which I understand to be asynchronous; and I’m combining that with some other asynchronous work in a Future. Since all of the work in the Future is asynchronous, do I need to pass a separate ExecutionContext to the PatternCS.pipe(…) call to avoid starving the actor messaging infrastructure?
// We must be careful not to close over any mutable actor state in this future.
CompletableFuture<PrivateProtocol> future =
accessTokenProvider.get(userKey, nrToken)
.thenApply(AccessTokenGrant::getToken)
.thenCompose(accessToken ->
permissionsGateway.byProjectId(host, accessToken, projectId, nrToken)
)
.thenApply(permissions ->
UserPermissionsInProject.powerfull(userKey, projectId, permissions)
)
.toCompletableFuture()
.<PrivateProtocol>thenApply(PrivateProtocol.RefreshSuccess::new)
.exceptionally(t -> new PrivateProtocol.RefreshFailure(projectId, t));
// Since the above future involves only non-blocking calls, I'm assuming that
// it's OK to use getContext().dispatcher() for the pipe.
PatternsCS.pipe(future, getContext().dispatcher()).to(getSelf(), replyTo);