Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/dart/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/228.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Asynchronous 如何在Dart中一次处理列表2中的项目_Asynchronous_Dart_Async Await - Fatal编程技术网

Asynchronous 如何在Dart中一次处理列表2中的项目

Asynchronous 如何在Dart中一次处理列表2中的项目,asynchronous,dart,async-await,Asynchronous,Dart,Async Await,我有一个视频目录,我想通过从Dart调用ffmpeg来压缩,但我想一次处理两个视频 import 'package:glob/glob.dart'; import 'dart:core'; void main(List<String> args) async { final videoFiles = Glob('E:/camera/*.mov'); var videos = videoFiles.listSync(); var videosInQueue = 0;

我有一个视频目录,我想通过从Dart调用ffmpeg来压缩,但我想一次处理两个视频

import 'package:glob/glob.dart';
import 'dart:core';

void main(List<String> args) async {
  final videoFiles = Glob('E:/camera/*.mov');
  var videos = videoFiles.listSync();
  var videosInQueue = 0;

  while (true) {
    if (videos.isEmpty) {
      print('No more videos to process');
      break;
    }

    if (videosInQueue < 2){
      print('\n$videosInQueue videos in the queue. Adding more...');
      var video = videos.removeLast();
      var videoInfo = await getVideoInfo(video);

      if (videoInfo['shouldProcess']) {
        videosInQueue += 1;
        var response = ProcessVideo(videoInfo['path'], videoInfo['outputName']);

        response.then((onValue) {
          videosInQueue -= 1;
        });
      }
    }else{
      continue;
    }
  }
}

Future<int> ProcessVideo(String path, String outputName) async {
  print('Processing $path');
  await Future.delayed(const Duration(seconds: 5));
  return 200;
}

当我运行这段代码时,它会将前两个视频添加到队列中,但它会卡在while循环中

输出:

0 videos in the queue. Adding more...
Processing E:/camera\recording0023-10-12-2019.mov

1 videos in the queue. Adding more...
Processing E:/camera\recording0024-10-12-2019.mov
我怀疑这个代码…:

response.then((onValue) {
          videosInQueue -= 1;
        });
被称为“视频队列”的次数不会减少。我怎样才能纠正这个问题

response.then((onValue) {
          videosInQueue -= 1;
        });