-
Notifications
You must be signed in to change notification settings - Fork 530
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
Point out cancelation semantics in fromCompletableFuture
scaladoc
#3644
Point out cancelation semantics in fromCompletableFuture
scaladoc
#3644
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.
Sorry, we should retarget this change at series/3.5.x
branch so it will be released sooner. Thanks btw!
* Note that cancelation is cooperative, and it's up to the `CompletableFuture` to respond to | ||
* interruption requests and handle cancelation appropriately. This means that if the | ||
* `CompletableFuture` computation is uncancellable (for example, it doesn't handle `Thread` | ||
* interruptions), there will be no 'fire and forget' semantics and by satisfying backpressure | ||
* guarantees, cancelation will wait for computation to complete. |
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.
I'm not sure about the comment about "thread interruptions". The JavaDoc for CompletableFuture#cancel
says this:
mayInterruptIfRunning - this value has no effect in this implementation because interrupts are not used to control processing.
WDYT about this?
* Note that cancelation is cooperative, and it's up to the `CompletableFuture` to respond to | |
* interruption requests and handle cancelation appropriately. This means that if the | |
* `CompletableFuture` computation is uncancellable (for example, it doesn't handle `Thread` | |
* interruptions), there will be no 'fire and forget' semantics and by satisfying backpressure | |
* guarantees, cancelation will wait for computation to complete. | |
* @note Cancelation is implemented by invoking the `CompletableFuture`'s `cancel()` method. | |
* It is up to the `CompletableFuture` to handle cancelation appropriately and indicate it has done so. | |
* This means that if the `CompletableFuture` indicates that it did not cancel, there will be no | |
* "fire-and-forget" semantics. Instead, to satisfy backpressure guarantees, the `CompletableFuture` | |
* will be treated as if it is uncancelable and the fiber will fallback to waiting for it to complete. |
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.
Uh-oh, probably the part on thread interruptions is really wrong. I like your rephrasing generally, but I would like to leave the reference that cancelation is cooperative. There are a few more mentions about it within CE's scaladocs. And maybe we need to remove the part on using the cancel
method on CF since it's the only way to cancel it, and very unlike smth will change for Java's API.
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.
but I would like to leave the reference that cancelation is cooperative. There are a few more mentions about it within CE's scaladocs.
Ahh, I'm sorry, you are right! This is used in many places.
Line 102 in 6a6db8f
First off, is *cooperative*. When one fiber calls `cancel` on another fiber, it is effectively a request to the target fiber. If the target fiber is unable to cancel at that moment for any reason, the canceling fiber asynchronously waits for cancelation to become possible. Once cancelation starts, the target fiber will run all of its finalizers (usually used to release resources such as file handles) before yielding control back to the canceler. Conversely, `interrupt` always returns immediately, even if the target `Thread` has not actually been interrupted. |
I was confusing with "cooperative polling" 😅 TIL.
Ok, how about this? (Feel free to make your own revision and push to the branch :)
* Note that cancelation is cooperative, and it's up to the `CompletableFuture` to respond to | |
* interruption requests and handle cancelation appropriately. This means that if the | |
* `CompletableFuture` computation is uncancellable (for example, it doesn't handle `Thread` | |
* interruptions), there will be no 'fire and forget' semantics and by satisfying backpressure | |
* guarantees, cancelation will wait for computation to complete. | |
* @note Cancelation is cooperative and it is up to the `CompletableFuture` to respond to the request | |
* by handling cancelation appropriately and indicating that it has done so. | |
* This means that if the `CompletableFuture` indicates that it did not cancel, there will be no | |
* "fire-and-forget" semantics. Instead, to satisfy backpressure guarantees, the `CompletableFuture` | |
* will be treated as if it is uncancelable and the fiber will fallback to waiting for it to complete. |
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.
Seems great to me. Thanks for adjusting and pushing this forward.
@armanbilge do you merge changes from |
We merge from |
6396a86
to
a16f3e5
Compare
a16f3e5
to
a59a31a
Compare
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.
Thank you, this is an excellent thing to note!
No description provided.