-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Remove InternalForInheritanceCoroutinesApi from Deferred<T> #4408
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Labels
Comments
Thanks! The use case is clear, and we already have things like https://kotlinlang.org/api/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines.flow/as-state-flow.html, so adding this is straightforward: #4410 |
Wow, that was fast, thanks @dkhalanskyjb . |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
What do we have now?
I want to return a
CompletableDeferred<T>
from a public API. I am returning it as aDeferred<T>
as I don't want the consumer of the API to be able to complete the deferred, as this would mess with the internals class returning the deferred. If I just return theCompletableDeferred<T>
, it can still be tempting for a consumer to upcastDeferred<T>
toCompletableDeferred<T>
and complete it.So I do the following instead:
This would be a clean solution, but unfortunately I get this warning:
What should be instead?
There should be a way to achieve the above scenario without relying on internal APIs. Either provide a function allowing to return a "locked" version of the deferred:
This is similar to
CompletableFuture<T>.minimalCompletionStage()
.Or remove
InternalForInheritanceCoroutinesApi
fromDeferred<T>
.Why?
This would allow basic encapsulation for Deferred.
The text was updated successfully, but these errors were encountered: