Skip to content

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.

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

@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