-
Notifications
You must be signed in to change notification settings - Fork 521
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
Added cancelable
#3460
Added cancelable
#3460
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.
Thanks, this is so much nicer than what I had 😁 🤦
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.
Related discussion: #2671.
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.
This makes perfect sense to me. In fact, I have a vague memory of double checking this was encodable with uncancelable
: the shape of cancelable
being added here was the main combinator for cancelation in early versions of cats-effect
|
||
```scala | ||
def readBytes(fis: FileInputStream) = | ||
IO blocking { |
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.
nit: seems you usually use IO.blocking
no?
The unit test does a pretty good job of demonstrating the use case. Reproducing here in more condensed form:
Under normal circumstances, the above would be a fancy version of
never
. The use ofcancelable
converts this into something which has the natural semantics: canceling the effect completes theDeferred
and unlocks the fiber. More usefully, this can be applied to effects constructed withblocking
ordelay
to make them safely cancelable in the case where some state can be mutated to prematurely terminate the effect.Generalizes #3459, as well as #3374