那么Dart等待移除吗?

时间:2018-11-27 11:37:45

标签: dart

等待删除“然后”吗?

为什么在以下情况下使用then会导致此错误:

// Error: [dart] The method 'then' isn't defined for the class 'String'. [undefined_method]

来自here

的修改后的代码
import 'dart:async';

Future<void> printDailyNewsDigest() async {
  var newsDigest = await gatherNewsReports();
  // Error: [dart] The method 'then' isn't defined for the class 'String'. [undefined_method]
  newsDigest.then(print);
  // print(newsDigest);
}

main() {
  printDailyNewsDigest();
  printWinningLotteryNumbers();
  printWeatherForecast();
  printBaseballScore();
}

printWinningLotteryNumbers() {
  print('Winning lotto numbers: [23, 63, 87, 26, 2]');
}

printWeatherForecast() {
  print("Tomorrow's forecast: 70F, sunny.");
}

printBaseballScore() {
  print('Baseball score: Red Sox 10, Yankees 0');
}

const news = '<gathered news goes here>';
const oneSecond = Duration(seconds: 1);

// Imagine that this function is more complex and slow. :)
Future<String> gatherNewsReports() =>
    Future.delayed(oneSecond, () => news);    

1 个答案:

答案 0 :(得分:2)

$Member不会“删除” function Get-DistributionGroupMemberRecursive ($Identity) { $GroupMembers = Get-DistributionGroupMember -Identity $Identity foreach ($Member in $GroupMembers) { if($Member.RecipientType -like "*Group") { Get-DistributionGroupMemberRecursive -Identity $Member.Identity } else { $Member } } } Get-DistributionGroupMemberRecursive -Identity some_address@domain ,但是它允许以更方便的语法编写异步代码,例如await,并且可以替换then。 br /> then然后由编译器重新写回到then

await延迟以下代码的执行,直到完成等待的异步操作的结果并返回结果值。
结果值不再是then,因此await不可用。