Skip to content
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

Merged
merged 6 commits into from
Feb 27, 2023
Merged

Conversation

djspiewak
Copy link
Member

The unit test does a pretty good job of demonstrating the use case. Reproducing here in more condensed form:

IO.deferred[Unit] flatMap { latch =>
  val badness = latch.get.uncancelable
  badness.cancelable(latch.complete(()).void
}

Under normal circumstances, the above would be a fancy version of never. The use of cancelable converts this into something which has the natural semantics: canceling the effect completes the Deferred and unlocks the fiber. More usefully, this can be applied to effects constructed with blocking or delay 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

@djspiewak djspiewak added this to the v3.5.0 milestone Feb 25, 2023
armanbilge
armanbilge previously approved these changes Feb 25, 2023
Copy link
Member

@armanbilge armanbilge left a 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 😁 🤦

Copy link
Contributor

@durban durban left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Related discussion: #2671.

core/shared/src/main/scala/cats/effect/IO.scala Outdated Show resolved Hide resolved
docs/faq.md Show resolved Hide resolved
SystemFw
SystemFw previously approved these changes Feb 26, 2023
Copy link
Contributor

@SystemFw SystemFw left a 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

docs/faq.md Outdated Show resolved Hide resolved
@djspiewak djspiewak merged commit 73a379d into typelevel:series/3.x Feb 27, 2023

```scala
def readBytes(fis: FileInputStream) =
IO blocking {

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants