processAllBlocksAsync method

Future<List<UDPipeResult>> processAllBlocksAsync(
  1. List<String> blocks
)

Processes blocks in micro-task batches to keep the UI responsive.

Implementation

Future<List<UDPipeResult>> processAllBlocksAsync(List<String> blocks) async {
  if (!isAvailable) return List.filled(blocks.length, UDPipeResult.empty);
  const kBatch = 5;
  final all = List<UDPipeResult>.filled(blocks.length, UDPipeResult.empty);
  for (var i = 0; i < blocks.length; i += kBatch) {
    await Future.delayed(Duration.zero);
    final end = (i + kBatch).clamp(0, blocks.length);
    final partial = processBatchPerBlock(blocks.sublist(i, end));
    for (var j = 0; j < partial.length; j++) {
      all[i + j] = partial[j];
    }
  }
  return all;
}