runGraph function

int runGraph(
  1. Graph graph,
  2. int iterations,
  3. double readFraction,
  4. ReactiveFramework framework,
)

Implementation

int runGraph(
  Graph graph,
  int iterations,
  double readFraction,
  ReactiveFramework framework,
) {
  final random = Random(0);
  final Graph(:sources, :layers) = graph;
  final leaves = layers.last;
  final skipCount = (leaves.length * (1 - readFraction)).round();
  final readLeaves = _removeElems(leaves, skipCount, random);

  late int sum;
  framework.withBatch(() {
    for (int i = 0; i < iterations; i++) {
      final sourceDex = i % sources.length;
      sources[sourceDex].write(i + sourceDex);

      for (final leaf in readLeaves) {
        leaf.read();
      }
    }

    sum = readLeaves.fold(0, (total, leaf) => total + leaf.read());
  });

  return sum;
}