Integration of MapRef into cats-effect
See original GitHub issueMapRef
is a fairly simple abstraction that is one of the most critical tools for more advanced concurrent state machines. I propose it move into cats-effect in std that way everyone can leverage it. The name is just what has been used, but its by no means the only name that could be used for it.
https://github.com/davenverse/mapref
trait MapRef[F[_], K, V] extends Function1[K, Ref[F, V]]{
def apply(k: K): Ref[F, V]
}
This is then implemented for a variety of implementations ConcurrentHashMap, Ref[F, Map[K, V]], Array[Ref[Map[K, V]], etc.
These all expose MapRef[F, K, Option[V]]
which when none are not present in the underlying storage and hence does not space leak per key on empty. This is then enhanced via defaulted which lifts MapRef[F, K, Option[V]] => MapRef[F, K, V]
where some default value is instead removed from the map. Giving you a fully keyed state machine with no changes to the underlying state machinery.
This is already the baseline for mules, single-fibered, ratelimit, lock, as well as its in process of use for keysemaphore, and used as a keyedcircuit for rediculous concurrent. As well as keypool advanced. The use cases continue to expand as a dominating number of state machines are actually keyed.
This is a fairly fundamental abstraction that enables a whole class of state machines that the current ref/deferred alone do not permit without space leak concerns or building something equivalent to this.
Your thoughts are appreciated.
Issue Analytics
- State:
- Created 2 years ago
- Reactions:6
- Comments:5 (5 by maintainers)
The bar is high, but he demos this like once or twice a week at work as the underpinning of something else. The uses are real!
I’ll try to get it done as soon as I can. 😄