typelevel / typelevel/cats-effect
"Single-Resourced"
Nobody has claimed this yet.
- Dominant language
- Scala
- Stars
- 2.2k
- Forks
- 576
- Avg merge
- 2d 11h
- Merged PRs (30d)
- 18
Description
Prompted by https://github.com/typelevel/cats-effect/issues/3376 I was thinking again about reference-counting resources.
In https://github.com/typelevel/cats-effect/issues/3376 we consider ResourceSupervisor as the Resource analog of Fiber's Supervisor.
A related question: is there a Resource analog of Chris' Single-Fibered? I think it may look very much like a reference-counted Resource.
I'm imagining a signature like this:
def prepare[F[_], A](resource: Resource[F, A]): F[Resource[F, A]]
I realize this is a suspicious looking signature so bear with me!
The semantics of the returned Resource would be:
- acquire:
- if the resource is not presently acquired, it will acquire it
- if the resource is currently being acquired, it will await that
- if the resource is already acquired, it will grab it and increment the counter
- release:
- if this is the sole owner of the resource, it will release it
- otherwise simply decrement the counter
Note that under this scheme the resource may be acquired more than once, if the count goes to zero and then starts increasing again.
This would be implemented by allocating a Ref to hold the state, hence the return signature in F[_].
In single-fibered, there is at most one fiber running the task at any given time. In single-resourced, there is at most one acquisition of the resource at any given time.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reading the ResourceSupervisor discussion linked in the issue, then compare the proposed Resource semantics with single-fibered and the mentioned Ref-based state. The issue does not name implementation files or tests; done would require settling the API and acquisition and release semantics before implementation.
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
- Mostly clear
- Newbie friendliness
- 25/100