hiero-ledger / hiero-ledger/hiero-consensus-node
Create a `Future` that implements `CompletionStage`
- Dominant language
- Java
- Stars
- 406
- Forks
- 226
- Avg merge
- 3d 4h
- Merged PRs (30d)
- 210
Description
### Problem
A long and illuminating conversation about `Future` vs. `CompletableFuture` can be found on #6291 [Implement the modular Pre-Handle Workflow](https://github.com/hashgraph/hedera-services/pull/6291#discussion_r1192541976). `CompletableFuture` is really nice to work with because it implements `CompletionStage`, whereas `Future` does not. We have many places where we use `Future`, but it lacks composability. `CompletableFuture` however exposes an API that allows code to "complete" the future. In many cases, we want to expose the composability features but **not** the completion features.
### Solution
We could introduce an interface, `HFuture` or something (trying to keep the name short, H for Hedera or Hashgraph). And this interface extends from `Future` and `CompletionStage`. And adds default methods for wrapping a `Future` or delegating to an executor service much like `CompletableFuture` does. And in fact, the (private hidden implementation) of `HFuture` (call it `HFutureImpl`) would actually use a `CompletableFuture` behind the scenes to make sure we get the right semantics.
Or maybe even simpler -- `HFuture` extends `Future` and `CompletionStage`, and `HFutureImpl` just extends from `CompletableFuture`, and in our API we work in terms of `HFuture`. That would probably result in almost no actual implementation logic and we get what we need.
I wish Java's Future had default methods for everything in `CompletionStage` and could implementation `CompletionStage`, but I guess that is not possible. If it were, we should actually look to contribute the fix upstream into Java so all `Future`s become `CompletionStage`. That would be even better.
### Alternatives
_No response_
Contributor guide
Research direction
Start by reading the Future-versus-CompletableFuture discussion on issue #6291, then compare the required Future and CompletionStage behavior described here. No source files or tests are named; done would require settling the HFuture API and implementation approach, then validating the resulting semantics in the affected uses.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- api, backend
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100