Another version to discuss.

```scala
private class SelfPopulatingMap[K, V] {
  private val store = TrieMap[K, Future[V]]()

  def putIfAbsent(k: K)(pf: K => V)(implicit ec: ExecutionContext): Future[V] = {
    val p = Promise[V]
    store.putIfAbsent(k, p.future) match {
      case Some(f) => f
      case None =>
        val workerFuture = Future(pf(k))(ec.prepare)
        p.completeWith(workerFuture)
        p.future
    }
  }
}
```