computeFileListEncryptionPromise function

Future<bool> computeFileListEncryptionPromise(
  1. FileListEncryptionPromise fileListEncryptionPromise, {
  2. OnCipherFinished? onCipherFinished,
})

Implementation

Future<bool> computeFileListEncryptionPromise(
    FileListEncryptionPromise fileListEncryptionPromise,
    {OnCipherFinished? onCipherFinished}) async {
  Completer<bool> encryptAllFilesCompleter = Completer();
  ReceivePort receivePort = await computeFileListEncryptionPromiseWithPorts(
    Isolate.current.controlPort,
    fileListEncryptionPromise,
  );

  int expectedResultsCount = fileListEncryptionPromise.filePromises.length;
  bool allSuccess = true;
  // Listen for results from the receive port
  await for (var result in receivePort) {
    // Process each result as it arrives
    CipherResult cipherResult = CipherResult.fromMap(result);
    if (onCipherFinished != null) {
      onCipherFinished(CipherResult.fromMap(result));
    }
    if (!cipherResult.success) allSuccess = false;
    expectedResultsCount--;
    if (expectedResultsCount == 0) {
      receivePort.close();
      encryptAllFilesCompleter.complete(allSuccess);
    }
  }

  return encryptAllFilesCompleter.future;
}