Skip to content

Idea: Managed resource map #1345

@djspiewak

Description

@djspiewak
trait Manager[F[_], K, V] {

  def +=(pair: (K, Resource[F, V])): F[Unit]

  def -=(key: K): F[Unit]

  def apply(key: K): F[Option[V]]

  def join(key: K): F[V]
}

object Manager {
  def apply[F[_]: Sync, K, V]: Resource[F, Manager[F, K, V]] = ???
}

The idea here is that it's often useful to have a concurrent map-like data structure which manages Resource lifecycles for you, indexed by some key (so you can retrieve the results). These resources can be submitted (via +=) and will be evaluated in background, with their value stored in the map once complete. Removing the key from the map would close the resource scope. Similarly, closing the resource scope on the Manager would close all constituent Resources and cancel any outstanding computations.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions