Skip to content

Commit

Permalink
TEST Call key.resolve/key.fallback separately for each cell in a cSCC.
Browse files Browse the repository at this point in the history
This is related to phaller#46 but the slowest solution possible.

As in OPAL every cell has its onw key we cannot rely on taking the first
key available. So we call key.resolve for every cell and apply the
result after all invocations.
  • Loading branch information
JanKoelzer committed Oct 12, 2018
1 parent 3eac268 commit 15b6c67
Showing 1 changed file with 20 additions and 18 deletions.
38 changes: 20 additions & 18 deletions core/src/main/scala/com/phaller/rasync/HandlerPool.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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. */
})
}

/**
Expand Down

0 comments on commit 15b6c67

Please sign in to comment.