-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Fix await/asDeferred for MinimalState implementations #2457
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
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good fix 👍
try { | ||
@Suppress("UNCHECKED_CAST") | ||
return get() as T | ||
@Suppress("UNCHECKED_CAST", "BlockingMethodInNonBlockingContext") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// mayInterruptIfRunning is not used | ||
(this as? CompletableFuture<T>)?.cancel(false) | ||
consumer.cont = null // shall clear reference to continuation to aid GC | ||
if (cont.isActive) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not a big fan of optimizations that work 0.01% of the time (when future completes after isDone
check but after whenComplete
): hard to test and reason about.
I may be too opinionated here tho
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep. It is indeed not needed anymore, where we (again) have fast-path via future.isDone
here.
Fixes #2456