diff --git a/core/src/main/scala/com/phaller/rasync/HandlerPool.scala b/core/src/main/scala/com/phaller/rasync/HandlerPool.scala index c01994d..1b27e4c 100644 --- a/core/src/main/scala/com/phaller/rasync/HandlerPool.scala +++ b/core/src/main/scala/com/phaller/rasync/HandlerPool.scala @@ -250,28 +250,30 @@ class HandlerPool( /** * Resolves a cycle of unfinished cells via the key's `resolve` method. */ - private def resolveCycle[K <: Key[V], V](cells: Iterable[Cell[K, V]]): Unit = - resolve(cells.head.key.resolve(cells)) + private def resolveCycle[K <: Key[V], V](cells: Iterable[Cell[K, V]]): Unit = { + val results = + cells.map(c => (c, c.key.resolve(cells).toMap.get(c))) // resolve for every cell separately but given the complete cSCC + .filter(_._2.isDefined) + val cellsToBeResolved = results.toMap.keys.toSeq + results.foreach({ + case (c, Some(v)) => execute(() => c.resolveWithValue(v, cellsToBeResolved)) + case _ => /* Cells should not be resolved, key.resolve did not return it. */ + }) + } + /** * Resolves a cell with default value with the key's `fallback` method. */ - private def resolveDefault[K <: Key[V], V](cells: Iterable[Cell[K, V]]): Unit = - resolve(cells.head.key.fallback(cells)) - - /** Resolve all cells with the associated value. */ - private def resolve[K <: Key[V], V](results: Iterable[(Cell[K, V], V)]): Unit = { - val cells = results.map(_._1).toSeq - for ((c, v) <- results) - execute(new Runnable { - override def run(): Unit = { - // Remove all callbacks that target other cells of this set. - // The result of those cells is explicitely given in `results`. - // c.removeAllCallbacks(cells) - // we can now safely put a final value - c.resolveWithValue(v, cells) - } - }) + private def resolveDefault[K <: Key[V], V](cells: Iterable[Cell[K, V]]): Unit = { + val results = + cells.map(c => (c, c.key.fallback(cells).toMap.get(c))) // resolve for every cell separately but given the complete cSCC + .filter(_._2.isDefined) + val cellsToBeResolved = results.toMap.keys.toSeq + results.foreach({ + case (c, Some(v)) => execute(() => c.resolveWithValue(v, cellsToBeResolved)) + case _ => /* Cells should not be resolved, key.resolve did not return it. */ + }) } /**