typelevel / typelevel/cats-effect

Cancelables

Open
#3,527 8 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Scala
Stars
2.2k
Forks
576
Avg merge
2d 11h
Merged PRs (30d)
18

Description

Hi all,

Hotswap is a useful feature, but it's only one use-case of a set of patterns involving resource allocation and handling.

In particular, Hotswap is an implementation (that may be too high-level) of a SerialDisposable from RxJava, or SerialCancelable from Monix. And there are other patterns that may be useful, and I can think of these …

SingleAssignCancelable, which is a cancelable reference that can only be set once. This is super useful in case you want to refer to a cancelable token of a resource that wasn't initialized yet. With it, you can build, for example, a Resource builder that does not wait for the acquisition of the underlying resource. E.g., you can easily build something like:

F[(A, F[Unit])] => Resource[F, F[A]]

(and I'd also propose the inclusion of something like this in Cats-Effect)

CompositeCancelable, which allows for composing multiple resources that can be disposed all at once. For example, I feel the need of getting rid of Resource chains from my main initialization logic, something similar to Scala's Using.Manager.

RefCountCancelable which allows for the sharing of a resource, only disposing it once all consumers are done with it.

I want to contribute them somewhere. Monix's execution/catnap subprojects have been a natural destination, but I no longer want to work on Cats-Effect utils that may get superseded by implementations in Cats-Effect proper. I'd like to contribute something like this to Cats-Effect. In particular, I really feel the need for SingleAssignCancelable.

Do you think these would be useful in std? I already have a working implementation, which I use in our project at $work, for SingleAssignCancelable, to go alongside that Resource[F, F[A]] utility. Would you like to see it on a PoC PR?

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reviewing the existing Hotswap and std APIs, then compare the proposed SingleAssignCancelable, CompositeCancelable, and RefCountCancelable abstractions with the linked RxJava, Monix, and Scala Using.Manager references. No file or test is named; done would require an agreed scope and a PoC PR showing which cancelable utilities belong in Cats-Effect std.

Written by the indexing model from the issue text.

Assessment

Tech stack
scala
Domain
backend
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.