'yield'关键字在颤动中起什么作用? [英] What does 'yield' keyword do in flutter?
本文介绍了'yield'关键字在颤动中起什么作用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
yield
关键字在Dart中实际上起什么作用?
What does the yield
keyword actually do in Dart?
推荐答案
yield
为周围的async*
函数的输出流添加一个值.就像return
,但不会终止该函数.
yield
adds a value to the output stream of the surrounding async*
function. It's like return
, but doesn't terminate the function.
请参见 https://dart.dev/guides/language/language-tour#generators
Stream asynchronousNaturalsTo(n) async* {
int k = 0;
while (k < n) yield k++;
}
执行yield语句时,它将对表达式的求值结果添加到流中.它不一定要挂起(尽管在当前的实现中会挂起).
When the yield statement executes, it adds the result of evaluating its expression to the stream. It doesn’t necessarily suspend (though in the current implementations it does).
这篇关于'yield'关键字在颤动中起什么作用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文